Collections method sort. - Java Collection Framework

Java examples for Collection Framework:Collections Utility Methods

Description

Collections method sort.

Demo Code

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

public class Main 
{
   public static void main(String[] args)
   {//  w  w  w  .  j  a  v a 2  s  .c  o m
      String[] suits = {"Hearts", "Diamonds", "Clubs", "Spades"};
      
      // Create and display a list containing the suits array elements
      List<String> list = Arrays.asList(suits); 
      System.out.printf("Unsorted array elements: %s%n", list);

      Collections.sort(list); // sort ArrayList
      System.out.printf("Sorted array elements: %s%n", list);
   } 
}

Result


Related Tutorials