Java Collection Tutorial - 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.

/*from  w w w. j  a  v  a2s .c  om*/
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.