How to Sort ArrayList of String and Integer in Java

In this tutorial you will learn how to sort ArrayList of String or Integer in Java.

We can easily sort an arraylist in ascending or descending order using Collections.sort() method.

Below I have shared simple example for each of them.

ArrayList in Java

Sort ArratList in Java

Example to Sort ArrayList of String

Below program sorts an arraylist of String type.

 

Output

Sort in ascending order
Android
IOS
Linux
Mac
Windows

Sort in descending order
Windows
Mac
Linux
IOS
Android

 

Example to Sort ArrayList of Integer

Below program sorts an arraylist of Integer type.

 

Output

Sort in ascending order
10
15
20
25
30

Sort in descending order
30
25
20
15
10

 

You can ask your queries by commenting below.

3 thoughts on “How to Sort ArrayList of String and Integer in Java”

  1. What if i create an arraylist it’s type Human , it contains names and ages
    And i want to sort names alone then sort ages ?

  2. Luciano Haddick

    Now you must have understood the importance of these interfaces. Let s see how to use them to get the sorting done in our way.

Leave a Comment

Your email address will not be published. Required fields are marked *