java.util.Collections.sort() Comparator Method


java.util.Collections.sort() Comparator Method

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String args[]) {  

      // create linked list object         
      LinkedList<Integer> list = new LinkedList<Integer>();  

      // populate the list
      list.add(-28);
      list.add(20);
      list.add(-12);
      list.add(8);

      // sort the list
      Collections.sort(list, null);  

      System.out.println("List sorted in natural order: ");      

      for(int i : list) {
         System.out.println(i+ " ");
      }
   }
}