• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Sorting ArrayList

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>
 
Marshal
Posts: 80234
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic