Java Arrays.sort(Object [] a)

Syntax

Arrays.sort(Object [] a) has the following syntax.

public static void sort(Object [] a)

Example

In the following code shows how to use Arrays.sort(Object [] a) method.


//  w  ww  . j  a v a  2  s  . co m
import java.util.Arrays;

public class Main {

   public static void main(String[] args) {

    // initializing unsorted Object array
    Object ob[] = {27, 11, 44,22,0};

    System.out.println(Arrays.toString(ob));

    // sorting array
    Arrays.sort(ob);

    System.out.println(Arrays.toString(ob));
  }
}

The code above generates the following result.