wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Sorting ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorting ArrayList" Watch "Sorting ArrayList" New topic
Author

Sorting ArrayList

Eshwar Prasad
Ranch Hand

Joined: Mar 21, 2008
Posts: 202

Please let me know how to sort the data in the below array list.




I know that we can put A4.get(0) and A4.get(1) in TreeSet and sort the list, but can the list be sorted just using above code like,

I used Collections.sort(A4) it is giving wrong results. Also, while using Collections.sort(A4), is the list sorted by taking A4.get(0) as a reference or A4.get(1) as reference.

Please let me know>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36475
    
  16
What are you getting? How are you sorting? Remember Collections#sort takes Comparable as its parameter, and I don't think Lists are usually Comparable. Strings are however, so you should be able to sort a List<String>.
Remember the order Strings are sorted in: ASCIIbetical.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting ArrayList
 
Similar Threads
Single table two column dependency query
== and equals in String Class
How many objects eligible for GC??
removing duplicates from the list?
dealing with compiler warnings