What is the key difference between TreeSet and HashSet?
ATreeSet allows null elements
BTreeSet maintains sorted order, HashSet does not
CHashSet is faster than TreeSet
DTreeSet is thread-safe
Correct Answer:
B. TreeSet maintains sorted order, HashSet does not
EXPLANATION
TreeSet implements SortedSet and maintains elements in sorted order with O(log n) operations. HashSet has O(1) average operations but no order guarantee.
In Java 2024-25, which enhancement improved record support in collections?
ARecords automatically implement Comparable
BRecords can be used as sealed collection types with pattern matching
CRecords eliminate the need for custom Comparators
DRecords are automatically thread-safe
Correct Answer:
B. Records can be used as sealed collection types with pattern matching
EXPLANATION
Java 21+ enhanced sealed classes and pattern matching, allowing records to be used with pattern matching in collection operations and switch statements for type-safe data handling.