Get all updates of Java4s
Follow Us: Email Newsletter

How To Sort An ArrayList In Java

Core Java » On Feb 17, 2014 { 4 Comments } By Sivateja

This is one of the famous interview questions for freshers and even for the experienced developers :-) let us see how to sort the ArrayList in java. We have a class Collections in java.util package, which will do this magic for us. Consider an example…

Output

Printing List before sorting……
22
33
11
cc
bb
aa
Printing List after sorting……
11
22
33
aa
bb
cc

You Might Also Like

  ♦ About Author ♦

Java4s_Author
sivateja@java4s.com
Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

4 Responses to “How To Sort An ArrayList In Java”
  1. mani says:

    the above program doest produce expected output…
    there is a problem in sorting…
    any one tell me the reason…???

  2. CAN U PLEASE WRITE THE ABOVE PROGRAM WITHOUT USING COLLECTIONS.SORT()METHOD

  3. Tarique Anwer says:

    How Collections.sort(al) methods invokes the compare() of Comparator or compareTo() of Comparable interface in case of custom sorting.
    It will be great if you could explain only internal working for the same. I know the implementations.

  4. MOHAMMAD SALEEM BASHA says:

    I need a java code for following question

    1. how to find missing elements in an array,if i give input like 1,2,3,4,7,8. the output will be generated as the missing elements are 5,6.

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.