Java Array sorting Java8
//1. Natural ordering
User[] sortedUserArray = Stream.of(userArray)
.sorted()
.toArray(User[]::new);
//2. Reverse ordering
User[] sortedUserArray = Stream.of(userArray)
.sorted(Comparator.reverseOrder())
.toArray(User[]::new);
//3. Custom Sorting
Comparator nameComparator = Comparator.comparing(Employee::getName)
.thenComparing(Employee::getId)
User[] sortedUserArray = Stream.of(userArray)
.sorted(nameComparator)
.toArray(User[]::new);
Cookies4Techies