Pin It

A simple Java program to sort elements in an ArrayList

A simple Java program to sort elements in an ArrayList

package com.hubberspot.examples;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ArrayListSorting {

   public static void main(String[] args) {		
		
       List shoppingSites = new ArrayList();
		
       shoppingSites.add("ebay");
       shoppingSites.add("amazon");
       shoppingSites.add("jabong");
       shoppingSites.add("zovi");
       shoppingSites.add("tradus");
       shoppingSites.add("flipkart");
       shoppingSites.add("homeshop18");
	
       System.out.println("Before Sorting : ");
       System.out.println(Arrays.toString(shoppingSites.toArray()));
	
       System.out.println("After Sorting : ");
       Collections.sort(shoppingSites);
		
       System.out.println(Arrays.toString(shoppingSites.toArray()));
 
       System.out.println("After Sorting in reverse : ");
       Collections.sort(shoppingSites, Collections.reverseOrder());
       
       System.out.println(Arrays.toString(shoppingSites.toArray())); 
   }
}




Output of the program : 

Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot