Ask about a particular java collections having following properties -


I want to ask about the collection that I can use in my project. The following are my requirements.

  1. It has a key-value pair. is a mobile field and the other is the distance.
  2. The mobile field is unique, but the distance is not unique.
  3. They should be stored in the ascending order of the distance area.
  4. I do not want to delete the duplicate distance (key-pair).

    I already distribute distance as the TreeMap value and take the distance as mobile.

    But it is removing duplicates and I can not even make mobile as a key, because otherwise it will sort the pair according to the value of the mobile. So please tell what to do.

      tree map tree = new tree map (); While (rsnext ()) // Distribution and crowd values ​​here tree. Abundant (dist, mob); } Set = Set. Tree.entrySet (); Iterator IRR = Set.itator (); Out.println ("Distance" + "Mobile"); While (IRHHXXext ()) {map. Entry M = (map entry). (); Out.println (m.getKey () + "" + m.getValue () + "\ n"); }     

    I want to get all the mobile numbers in the order of their respective increasing distance. This is what I have tried so far, but the problem with it is destroying the duplicate distance.

      TreeMap & lt; Integer, LinkedList & lt; Integer & gt; & Gt; Use the same TreeMap with the parameter. TMap = New TreeMap & lt; Integer, LinkedList & lt; Integer & gt; & Gt; ();   

    Consider the value in the form of distance here and the price in the form of mobile. According to your statement, there are not many mobile prices for the same distance (since the distance is not unique). Therefore, we can be linkedldist or arree for the price area.

    The treemark will store the key in a way that way, you can print the keymark for the key and the treemark based on all the values.

    The complete code is given below,

      import java.util.Collections; Import java.util.LinkedList; Import java.util.TreeMap; Public Class Multi-Well Collection {Public Static Wide Men (String [] AGR) [// Todo Auto-Generated Method Stub Multi-Well Collection Emolution = New Multi-Well Collection (); Treemark & ​​Lt; Integer, linked list & lt; Integer & gt; & Gt; TMap = New TreeMap & lt; Integer, LinkedList & lt; Integer & gt; & Gt; (); MCollection.addMobileNumberByDistance (TMP, 40, 65655423); MCollection.addMobileNumberByDistance (TMP, 40, 76785647); MCollection.addMobileNumberByDistance (TMP, 40, 85785852); MCollection.addMobileNumberByDistance (TMP, 40, 96786344); MCollection.addMobileNumberByDistance (TMP, 40, 57657354); MCollection.addMobileNumberByDistance (TMP, 20, 13543353); MCollection.addMobileNumberByDistance (TMP, 20, 23453456); MCollection.addMobileNumberByDistance (TMP, 30, 33353544); MCollection.addMobileNumberByDistance (TMP, 30, 43534554); MCollection.addMobileNumberByDistance (TMP, 30, 59789785); mCollection.printMobileNumbersByDistance (tMap); } Public Zero addMobileNumberByDistance (TreeMap & lt; integer, linked list & lt; integer & gt; gt; gt; gt; template, int distance, int mobile no) {linked list & lt; Integer & gt; List = null; If (tMap.get (distance) == faucet) {list = new linked list & lt; Integer & gt; (); } And {list = tMap.get (distance); } List.push (mobileNo); TMap.put (distance, list); } Public Zero PrintMobile NumbersBydistance (Trimark & ​​Lt; Integer, Linkedist & lt; integer & gt; & gt; distNumberMap) {Linkedlist & lt; Integer & gt; List; For (int n: distNumberMap.keySet ()) {list = distNumberMap.get (n); Collections.sort (list); // If the mobile line does not need to sort for any differences, then add this line (int k: list) {System.out.println ("key" + n + "value" + K); }}}}    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -