Question 1
The list below is sorted with a Comparator constant declared in java.lang.String. What is printed? ```java import java.util.*; public class Main { public static void main(String[] args) { List<String> names = new ArrayList<>(List.of("Delta", "echo", "Alpha", "bravo")); names.sort(String.CASE_INSENSITIVE_ORDER); System.out.println(names); } } ```
A. [Alpha, Delta, bravo, echo]
This is the natural (compareTo) ordering, where all upper-case letters sort before all lower-case ones because of their UTF-16 code points — exactly the pitfall the case-insensitive comparator avoids.
B. [Delta, echo, Alpha, bravo]
This is the unsorted input order; the list is actually reordered by the comparator.
C. [Alpha, bravo, Delta, echo]Correct answer
Correct — the case-insensitive comparator folds case before comparing, giving alpha < bravo < delta < echo while leaving each element's original capitalisation intact.
D. [alpha, bravo, delta, echo]
Assumes sorting lower-cases the elements; a comparator only decides order and never mutates the strings, so their original capitalisation is preserved.
Explanation
The case-insensitive comparator compares characters after folding their case, so ordering follows the alphabet regardless of capitalisation, unlike natural String ordering where every upper-case letter precedes every lower-case one. Crucially, a comparator only determines order and never alters the elements, so each string keeps the capitalisation it started with.