Sorting ArrayList using Java Collections framework

Sorting ArrayList using Collections


/**
 * 
 */
package com.sort;

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

/**
 * @author CodeDairy
 *
 */
public class ArrayListSorting {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		List arrayList = new ArrayList();
		
		arrayList.add("java");
		arrayList.add("sort");
		arrayList.add("array");
		
		System.out.println(arrayList);
		Collections.sort(arrayList);
		System.out.println(arrayList);
		
	}

}

Out of the above program

Line No.1 : shows the output before the sort
Line No.2 : shows the output after the sort


1. [java, sort, array]
2. [array, java, sort]


Leave a Comment