with Certified Solutions
What is the main purpose of the Java Collections Framework?
✔✔ To provide a set of reusable data structures and algorithms for managing collections of
objects
What is the difference between an ArrayList and a LinkedList in Java?
✔✔ An ArrayList is backed by a dynamic array, providing fast random access, while a
LinkedList uses a doubly linked list, making insertions and deletions faster
Which interface does every collection class in Java implement directly or indirectly?
✔✔ The Collection interface
What method is used to add an element to an ArrayList?
✔✔ The add() method
What happens when you try to insert a duplicate key into a HashSet?
✔✔ The duplicate key is ignored since HashSet does not allow duplicate values
1
, Which collection class maintains elements in the order they were inserted?
✔✔ The LinkedHashSet class
What is the default capacity of an ArrayList when it is first created without specifying a size?
✔✔ 10
How does a HashMap handle collisions?
✔✔ By using a technique called chaining, where multiple elements are stored in a bucket using a
linked list
Which method is used to retrieve a value from a HashMap using a key?
✔✔ The get() method
What does the iterator() method in a collection return?
✔✔ An Iterator object that can be used to traverse elements in the collection
What is the key difference between HashMap and TreeMap?
2