ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
Set<String> t = new TreeSet<>(List.of("apple", "Banana", "cherry"));
System.out.print(t);
  1. A. [apple, Banana, cherry]
  2. B. [cherry, Banana, apple]
  3. C. [apple, cherry, Banana]
  4. D. [Banana, apple, cherry]

Correct answer: D. [Banana, apple, cherry]

TreeSet sorts by String's natural order, which compares character codes. Uppercase letters (65–90) come before lowercase (97–122), so Banana sorts first.

More OOP with C++ and Java questions

Exams that ask this topic