Oracle
1Z0-819 · Question #94
Given the Person class with age and name along with getter and setter methods, and this code fragment: List<Person> persons = new ArrayList(List.of(new Person(44, "Tom"), new Person(40, "Aman"), new…
The correct answer is D. Aman Peter Tom. See the full explanation below for the reasoning.
Question
Given the Person class with age and name along with getter and setter methods, and this code fragment:
List<Person> persons = new ArrayList(List.of(new Person(44, "Tom"),
new Person(40, "Aman"),
new Person(40, "Peter")));
persons.sort(Comparator.comparing(Person::getAge)
.thenComparing(Person::getName));
persons.forEach(p1->System.out.print(" " +p1.getName()));
What will be the result?
Options
- AAman Tom Peter
- BTom Aman Peter
- CPeter Aman Tom
- DAman Peter Tom
How the community answered
(49 responses)- A12% (6)
- B8% (4)
- C4% (2)
- D76% (37)
Community Discussion
No community discussion yet for this question.