Sorting a List

// Create a list
String[] strArray = new String[] {"z", "a", "C"};
List list = Arrays.asList(strArray);

// Sort
Collections.sort(list);
// C, a, z

// Case-insensitive sort
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
// a, C, z

// Reverse-order sort
Collections.sort(list, Collections.reverseOrder());
// z, a, C

// Case-insensitive reverse-order sort
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
Collections.reverse(list);
// z, C, a

Comments

28 May 2010 - 12:35am by arulvenkatesan .m (not verified)

good , Is better of think source code in java

13 Jul 2010 - 12:36am by thematt (not verified)

THIS IS AWESOME...the most resourceful site i've ever visited. thanks

16 Nov 2010 - 5:49am by Anonymous (not verified)

AAAAAAAAAAAAAAAAAAAAAAH HOW DO U DO BUBBLE SORT OR SELECTION SORT!

31 Dec 2010 - 10:44pm by Cheryl (not verified)

I just want to be able to sort a list alphabetically on a notepad. I don't know how to use the codes or where to put them (don't be rude :D)to make a program work.

20 Feb 2011 - 8:42am by Anonymous (not verified)

This is actually sorting an array, not a list. Does anyone know how to sort a linked list?

9 May 2011 - 9:46am by Anonymous (not verified)

puto

9 May 2011 - 9:47am by Anonymous (not verified)

puto

17 Aug 2011 - 11:05pm by Anonymous (not verified)

thanks it helped me a lot

24 Apr 2012 - 5:10am by Electrical test equipment (not verified)

I feel strongly about information and love learning more on this. If possible, as you gain expertise, It is extremely helpful for me. would you mind updating your blog with more information?

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.