Results 1 to 7 of 7
Thread: Sorting a treemap by values?
- 03-18-2012, 06:46 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 13
- Rep Power
- 0
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?
- 03-18-2012, 09:16 PM #2
Member
- Join Date
- Mar 2012
- Posts
- 13
- Rep Power
- 0
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
- 03-18-2012, 09:38 PM #3
Re: Sorting a treemap by values?
Not an advanced topic. Moving to New to Java.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-19-2012, 12:34 AM #4
Member
- Join Date
- Mar 2012
- Posts
- 13
- Rep Power
- 0
- 03-19-2012, 03:07 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 13
- Rep Power
- 0
Re: Sorting a treemap by values?
Bump... still need help!!!
- 03-19-2012, 03:27 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
- 03-19-2012, 03:54 PM #7
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
Re: Sorting a treemap by values?
You can't. Plenty of workarounds though. Did you try anything Google suggested?
Similar Threads
-
Help Plz !! SORTING OID VALUES !!!
By srinboss in forum New To JavaReplies: 1Last Post: 12-03-2011, 10:06 PM -
sorting a hash map without creating a new treemap
By aisha05 in forum New To JavaReplies: 7Last Post: 07-22-2011, 09:11 AM -
Sorting string Array Values
By Zerpol in forum New To JavaReplies: 1Last Post: 01-14-2011, 07:08 AM -
sorting variable values in ascending order?
By jeffrey in forum New To JavaReplies: 0Last Post: 07-14-2009, 07:59 AM -
Sorting Elements in a TreeMap
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks