Graded A+
What is the primary purpose of the Java Collections Framework?
✔✔ To provide a set of interfaces and classes for handling groups of objects efficiently.
How does an ArrayList differ from an array in Java?
✔✔ An ArrayList is dynamically resizable, while an array has a fixed size.
What is the key difference between HashSet and TreeSet in Java?
✔✔ HashSet does not maintain order, while TreeSet maintains elements in sorted order.
What method is used to check if a HashMap contains a specific key?
✔✔ The `containsKey()` method.
Which interface in the Java Collections Framework represents a resizable array?
✔✔ The `List` interface.
1
, How does a LinkedList differ from an ArrayList?
✔✔ A LinkedList provides better performance for insertions and deletions, while an ArrayList is
faster for random access.
What does the `Map` interface in Java represent?
✔✔ A collection of key-value pairs where each key is unique.
How can you iterate over a HashMap in Java?
✔✔ By using an iterator, a for-each loop on `entrySet()`, or a lambda expression with
`forEach()`.
What is the main purpose of the `Comparator` interface in Java?
✔✔ To define custom sorting logic for objects.
How does a PriorityQueue order its elements?
✔✔ It orders elements based on their natural ordering or a provided comparator.
Which collection class allows duplicate elements but maintains insertion order?
2