nerdexam
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)
  • A
    12% (6)
  • B
    8% (4)
  • C
    4% (2)
  • D
    76% (37)

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice