Sorting a treemap by values?
Ok guys so I have figured out how to do the treemap now and it sorted the entrys in alphabetical order and prints thee averages. Next I need to sort Treemap based on the values.
I think I have to somehow pass the Treemap to an arraylist, sort the arraylist and then pass it to a hashmap and then print the hashmap but this is really confusing..
Do I need to make a new class that implements comparable or something?
Re: Sorting a treemap by values?
Ok abit of an update basically I type this.
System.out.println(myMap.values()); and it prints out
[1.0, 7.5, 2.9, 5.0]
I need to pass myMap.values() to an Array so I can sort that array and then print it out again so the values will be in highest order first but I just can't figure out the line of code that will change map.values() into an array
Re: Sorting a treemap by values?
Not an advanced topic. Moving to New to Java.
db
Re: Sorting a treemap by values?
Quote:
Originally Posted by
DarrylBurke
Not an advanced topic. Moving to New to Java.
db
If it isn't advanced maybe you can answer it?
Re: Sorting a treemap by values?
Bump... still need help!!!
Re: Sorting a treemap by values?
If it's only for display you could Collections.sort() that array.
That's assuming it's a List, of course.
Re: Sorting a treemap by values?
You can't. Plenty of workarounds though. Did you try anything Google suggested?