Simple Example of Sorting the elements in Java .

Simple Example of Sorting the elements in Java .

import java.util.*;

class Test9{

public static void main(String args[]){

ArrayList al=new ArrayList();

al.add("Hello");

al.add("Java");

al.add("Programming");

al.add("Fun");

Collections.sort(al);

Iterator itr=al.iterator();

while(itr.hasNext()){

System.out.println(itr.next());

}}}

Output: Fun
                 Hello
                 Java
                 Programming
 

Read More →