0

I have an xml that looks like :

<Order OrderNo="1">
 <OrderLines LineNo="1" Qty="10"/>
 <OrderLines LineNo="2" Qty="7"/>
 <OrderLines LineNo="3" Qty="10"/>
 <OrderLines LineNo="4" Qty="4"/>
 <OrderLines LineNo="5" Qty="1"/>
</OrderLines>
</Order>

I need to store the OrderLines in a map based on descending value of qty. I was thinking about a TreeMap, but then it expects only unique values for keys. In my case, the Qty can be same for multiple lines.

I am thinking about having the Qty as Key and it may not be unique.

Any help on this anyone?

SMA_JAVA
  • 471
  • 4
  • 9
  • 18
  • Can you specify: do you need keys to be unique, or not? – Sergey May 03 '17 at 09:26
  • 1
    Possible duplicate of [Sort a Map by values (Java)](http://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values-java) – Burak Akyıldız May 03 '17 at 09:32
  • Just wanna add same link as @BurakAkyıldız dose. If you not find answer there, please, write your concerns. – Sergey May 03 '17 at 09:34
  • so i want map my to look like : – SMA_JAVA May 03 '17 at 09:59
  • @SMA_JAVA thats just make no sense. How could you get values then? What's you expect as output in `get(10)` in your code? – Sergey May 03 '17 at 10:13
  • Since I am expecting this map to be sorted in descending order, my first value will always be the maximum value for Qty. I will just always take first entry from the map (the max value for Qty). I dont really want to do a get(10). – SMA_JAVA May 03 '17 at 10:18
  • Then why you need a whole map for that? You could just store `maxValue`, or store both *LineNo* and *Qty*. – Sergey May 03 '17 at 10:21
  • I am not sure I entirely got what you said. Can you please explain a bit more? – SMA_JAVA May 03 '17 at 10:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143264/discussion-between-sergey-and-sma-java). – Sergey May 03 '17 at 10:30

0 Answers0