Update lambda expression used for comparator

Updating lambda expression in order to obtain natural ordering of customers based on their age
This commit is contained in:
Honey Kakkar
2022-09-21 13:39:01 +00:00
committed by GitHub
parent ddebe806c4
commit 74f92e758d

View File

@@ -47,7 +47,7 @@ public class CustomerService {
customers.sort(Comparator.comparingInt(Customer::getAge));
//pure lambda expression
Collections.sort(customers, (c1, c2) -> c1.getAge() - c1.getAge()); //we careful when using this as it can cause overflow
Collections.sort(customers, (c1, c2) -> c1.getAge() - c2.getAge()); //we careful when using this as it can cause overflow
}
private static List<Customer> getCustomers(){