Table of Content

How to sort elements in Object Array in Java?

Declaration :

Explanation :

Purpose The java.util.Arrays.sort(Object[]) method sorts the specified array of Objects into ascending order according to the natural ordering of its elements.
Parameters a ===> This is the array to be sorted.
Return Value This method does not return any value.
Exception ClassCastException — if the array contains elements that are not mutually comparable (for example strings and integers).

Java Program : Example

Below example will explain java.util.Arrays.sort() method.

Output of Program :