Making a "treeMap" object, using "String keys" and "Float values" that its shorted by the "Float values"
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Manuel_Nikiforakis
Posted On:   Thursday, February 7, 2002 11:50 PM

I am trying to Make a treeMap object (using String keys and Float values ) that it is shorted by the Float values and not by the natural order of the keys. I know the constructor takes custom comparators, but I cant figure out how to use it. - I did read all the stuff about collections in the java tutorials, but I'm still confused -
Can someone pls help me ! ?
Thanks

Re: Making a "treeMap" object, using "String keys" and "Float values" that its shorted by the "Float values"

Posted By:   Christopher_Schultz  
Posted On:   Friday, February 8, 2002 05:26 AM

I don't think you can do this, especially using a Comparator. If you provide a custom Comparator, you'll end up only being able to compare different String objects (the keys).



Why do you want to sort the structure by the floating point values? In this scenario, the TreeMap doesn't make any sense; the keys are sorted (by definition) to allow fast lookups of data.



Consider using a separate structure to store your values, or have a parallel structure (perhaps a TreeMap) which has your keys and values in reversed roles (key=Float, value=String).



-chris
About | Sitemap | Contact