Implement the Comparable interface in the class your objects are from and pass your array to the sort method which takes only one parameter.
With Java 8, you can use a reference method.
Also, it's possible to compare on multiple fields using thenComparing methods.
A Comparable interface in Java is used to order user-defined objects. Here, the Student class implements Comparable so that we can use Arrays.sort () to sort an array of Student class objects.
Sorting an array of objects becomes easy with the Lambda functions in Java 8 without implementing the Comparable interface.