← Quiz: Comparable vs Comparator: all 10 questions
Quiz: Comparable vs Comparator · Question 8 of 10
What does this print? (code)
What does this print?
import java.util.*;
public class Main {
public static void main(String[] args) {
List<Integer> a = new ArrayList<>(List.of(3, 10, 7));
a.sort(Comparator.reverseOrder());
System.out.println(a);
}
}
- A.[3, 7, 10]
- B.[10, 7, 3]
- C.[7, 10, 3]
- D.[3, 10, 7]
Answer & explanation
Correct answer: [10, 7, 3]
reverseOrder flips the natural (numeric) order, so the largest comes first.
Can you get the rest right without peeking?
Take the timed Quiz: Comparable vs Comparator quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →