·
Given:
What is printed?
- Jeanne
- Ian
- Geertjan
- An exception is thrown
- Compilation fails
#java #certificationquestion #ocp
The Stream.min finds the minimum element of the stream according to the provided comparator.
A comparator compares its two arguments for order, returning a negative integer, zero, or a positive integer as the first argument is less than, equal to or greater than the second.
Here, the comparator always returns a positive number. This means an element is always deemed greater than the following one.
So, the last Champion instance is considered the minimum element, and "Geertjan" get printed out.