[thelist] Java: Sorted Map by value ?

Bojan Tesanovic btesanovic at gmail.com
Wed Sep 3 14:20:25 CDT 2008


Hi All,

just trying to do some simple thing in Java and I can't find  
Container (Map) in java.util classes that maintains value sorting and  
allows duplicate values though its easy to do it in PHP

What I found so far is TreeMap that sorts keys though I don't need it :)

here is what I need
I have pairs of <ProductID>,<Price>

ValueSortedMap.add(ProductID,price);
......

I want ValueSortedMap  to be sorted be price and of course it needs  
to support duplicate values as prices can be same for different  
products (ProductID).

Is there a simple solution for this in Java.



For those who knows PHP  simpler to explain through code
$array = array("iPod"=>203, "nanoPod" => 201, "microPod"=>500, "iPod  
Blue"=>203);
//asort — Sort an array and maintain index association
asort($array);




Note: ProductID is unique.



Bojan Tesanovic
http://www.carster.us/







More information about the thelist mailing list