Intermediate Java Collections: Core Concepts and Usage
Test your understanding of Java Collections and their practical applications.
Questions in this quiz
12 questions on Intermediate Java Collections: Core Concepts and Usage. Work through them here, then start the quiz to answer them and see your score.
1.Which Java collection class allows you to store elements in a key-value pair format and ensures that the keys are unique?
- ALinkedList
- BHashMap
- CHashSet
- DArrayList
2.What is the main difference between a HashSet and a TreeSet in Java?
- AHashSet is synchronized, TreeSet is not
- BHashSet allows duplicates, TreeSet does not
- CTreeSet allows null elements, HashSet does not
- DTreeSet maintains sorted order, HashSet does not
3.Which method would you use to add an element to a specific position in an ArrayList?
- Aappend(E element)
- Binsert(int index, E element)
- Cadd(int index, E element)
- Dput(int index, E element)
4.What will be the output of the following code snippet? List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add(1, "C"); System.out.println(list);
- A[C, A, B]
- B[B, C, A]
- C[A, B, C]
- D[A, C, B]
5.Which Java collection class is best suited for implementing a stack?
- ATreeMap
- BHashSet
- CArrayList
- DLinkedList
6.What is the time complexity of searching for an element in a HashMap by key?
- AO(n log n)
- BO(n)
- CO(log n)
- DO(1)
7.Which interface does the Java LinkedList class implement to allow it to be used as a queue?
- AQueue
- BList
- CDeque
- DSet
8.Which method is used to remove all elements from a Java Collection?
- Aclear()
- Bdelete()
- CremoveAll()
- Dpurge()
9.What is the main advantage of using a TreeMap over a HashMap?
- AFaster access time
- BAllows duplicate keys
- CMaintains keys in sorted order
- DConsumes less memory
10.Which Java collection framework class is synchronized by default?
- AHashMap
- BVector
- CArrayList
- DHashSet
11.What will be the result of the following code? Set<String> set = new HashSet<>(); set.add("A"); set.add("B"); set.add("A"); System.out.println(set.size());
- A4
- B2
- C3
- D1
12.Which of the following is a characteristic of a LinkedHashMap?
- AAllows null keys
- BIs synchronized
- CDoes not allow duplicate values
- DMaintains insertion order