0
List<Employee> listObj = new ArrayList<Employee>();
Employee e1  = new Employee("chaman", "gupta", 22);
Employee e2  = new Employee("aman", "gupta", 24);
Employee e3  = new Employee("raj", "sharma", 28);
Employee e4  = new Employee("mohit", "sharma", 28);

listObj.add(e1);
listObj.add(e2);
listObj.add(e3);
listObj.add(e4);

Employee e = listObj.stream().max(Comparator.comparing(Employee :: getAge)).get();
System.out.println(e);

it is giving me only single name i want all name of list which have max age

Vinay Hegde
  • 1,424
  • 1
  • 10
  • 23
chaman gupta
  • 1
  • 2
  • 2
  • 2
    Does this answer your question? [How can I retrieve all of the maximum values from a list?](https://stackoverflow.com/questions/18299087/how-can-i-retrieve-all-of-the-maximum-values-from-a-list) – Lang Jun 17 '20 at 17:54
  • @Naman I think OP want's solution using stream API(as he tried) , tagged question don't have any stream solution. And this one will be right duplicate https://stackoverflow.com/questions/54347184/how-to-get-all-objects-having-the-same-max-value-with-java-streams – Eklavya Jun 17 '20 at 18:12
  • 1
    @Eklavya sure. might have been amissing tag, have updated the duplicate for other relevant tags as well. – Naman Jun 17 '20 at 18:46

0 Answers0