May 28

This post is also available in: German

The non-sorted Collections can be sorted with Collections.sort(<Name>);

Here an example:

List a = new ArrayList<Integer>();
a.add(7);
a.add(3);
a.add(1);
a.add(5);

System.out.println(“Before sorting:”);

for (int i = 0; i < a.size(); i++)

System.out.println(a.get(i));

Collections.sort(a);

System.out.println(“after sorting”);

for (int i = 0; i < a.size(); i++)

System.out.println(a.get(i));

Output:

Before sorting:
7
3
1
5
After sorting:
1
3
5
7

3T6DZE5Q74SW

  • Print
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • RSS
  • Blogosphere
  • email
  • PDF
  • Wikio
  • Technorati
  • Digg
  • DZone

Leave a Reply

preload preload preload
http://www.wikio.de Blog Top Liste - by TopBlogs.de Blogverzeichnis - Blog Verzeichnis bloggerei.de Bloggeramt.de Software
Webbhotell Top Blogs