java sort objects by field code example
Example 1: java sort arraylist of objects by field descending
List<User> sortedUsers = users.stream()
.sorted(Comparator.comparing(User::getCreatedOn).reversed())
.collect(Collectors.toList());
Example 2: sort a collection based on one value java
Collections.sort(agentDtoList, (o1, o2) -> o1.getCustomerCount() - o2.getCustomerCount());