To sort values in ArrayList, we use Collections class, and invoke sort() method. consider this example:
package java8s;
import java.util.*;
public class SortCollectionDemo {
public static void main(String[] args)
{
List li = new ArrayList();
li.add("Santosh");
li.add("Akshay");
li.add("Tapuuu");
li.add("Millan);
li.add("Rakesh");
Collections.sort(li);
for(String temp: li)
{
System.out.println("Countries : "+temp);
}
}
}
Output:
Akshay
Millan
Rakesh
Santosh
Tapuuu
No comments:
Post a Comment