views:

8517

answers:

3

I am using TreeBidiMap from the apache collections library. I want to sort this on the values which are doubles.

My method is to retrieve a Collection view of the values using Collection coll = themap.values(). Which naturally works fine. Main Question: I now want to know how I can convert/cast (not sure which is correct) coll into a List so it can be sorted.

I then intend to iterate over the sorted List object, which should be in order and get the appropriate keys from the TreeBidiMap "themap" using themap.getKey(iterator.next()) where the iterator will be over the list of doubles.

+7  A: 
List list = new ArrayList(coll);
Collections.sort(list);
Paul Tomblin
A: 

Something like this should work:

List theList = new ArrayList(coll);
Jack Leow
+4  A: 
Collections.sort( new ArrayList( coll ) );

:P

OscarRyz
Missing a reference to access ArrayList?
Zach Scrivena
@Zach: mmhh good point. I knew there was a reason for me to mark this as CW. BTW Paul's ans is the one. I don't know why he has only my uv.
OscarRyz