• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding sorting of a list object

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

i want to sort elements of array list.so i written the below code.may i know why its not displaying in ascending order.
List l=new ArrayList();
l.add("100");
l.add("300");
l.add("10");
l.add("20");
l.add("400");
System.out.println(" before sorting"+l);
Collections.sort(l);
System.out.println(" after sorting"+l);

output:
before sorting[100, 300, 10, 20, 400]
after sorting[10, 100, 20, 300, 400]

regards,
rama krishna.Y
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your elements are displayed in ascending order. That is the ascending order for Strings.
If you want the numeric ascending order, drop those quotes and add numbers to your list.
 
yekkala krishna
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi costi,

Many Thanks !!
now it is working fine.

Regards
Ramakrishna
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good
 
reply
    Bookmark Topic Watch Topic
  • New Topic