QCM - Java Collections (50 Questions)
1. What does a Java Collection represent?
A) A single object
B) A group of objects
C) Only numbers
D) Only strings
2. Which package contains Java Collection classes?
A) java.io
B) java.sql
C) java.util
D) java.lang
3. Which interface is NOT a child of the Collection interface?
A) List
B) Set
C) Map
D) Queue
4. Which class implements the List interface?
A) HashSet
B) ArrayList
C) TreeMap
D) HashMap
5. In which case is LinkedList preferred over ArrayList?
A) Frequent random access
B) Frequent addition and removal
C) Less memory consumption
D) Sorting data
6. Which of the following allows duplicate elements?
A) Set
B) HashSet
QCM - Java Collections (50 Questions)
C) List
D) TreeSet
7. Which method adds an object to a Collection?
A) put(Object o)
B) append(Object o)
C) add(Object o)
D) insert(Object o)
8. The method isEmpty() in Collection returns:
A) Object
B) Boolean
C) Integer
D) Array
9. Which interface maintains insertion order?
A) Set
B) List
C) Map
D) Queue
10. Which class is NOT a part of the Java Collection Framework?
A) ArrayList
B) HashMap
C) Scanner
D) LinkedList
11. Which method retrieves an element from a List by index?
A) get()
B) retrieve()
C) fetch()
D) obtain()
12. Which class implements Set interface?
QCM - Java Collections (50 Questions)
A) ArrayList
B) HashSet
C) LinkedList
D) Vector
13. What happens when you add a duplicate in a HashSet?
A) Added twice
B) Replaces old
C) Ignored
D) Throws error
14. Which collection does not maintain order?
A) ArrayList
B) LinkedHashSet
C) HashSet
D) LinkedList
15. Which class implements both List and Deque interfaces?
A) HashSet
B) LinkedList
C) TreeSet
D) PriorityQueue
16. Which method removes an element by value in Collection?
A) delete()
B) remove()
C) eliminate()
D) destroy()
17. In a HashMap, keys must be:
A) Unique
B) Duplicate
C) Null always
QCM - Java Collections (50 Questions)
D) Primitive types
18. Which structure stores elements in key-value pairs?
A) List
B) Set
C) Map
D) Queue
19. TreeSet elements are sorted by:
A) Insertion order
B) Random order
C) Natural ordering
D) Hash code
20. Which method checks if a Collection contains an object?
A) has()
B) find()
C) contains()
D) search()
21. Which interface uses FIFO (First In First Out)?
A) List
B) Set
C) Queue
D) Map
22. PriorityQueue orders elements by:
A) Hash code
B) Insertion time
C) Priority
D) Size
23. LinkedList allows:
A) Only FIFO
QCM - Java Collections (50 Questions)
B) Only random access
C) Duplicates
D) Only unique elements
24. The method to remove all elements from a Collection:
A) deleteAll()
B) clear()
C) removeAll()
D) empty()
25. In ArrayList, access time is:
A) Constant
B) Linear
C) Quadratic
D) Random
26. HashSet belongs to which package?
A) java.util
B) java.sql
C) java.io
D) java.lang
27. LinkedHashSet maintains:
A) Random order
B) Sorted order
C) Insertion order
D) No order
28. Which Collection method returns the size?
A) length()
B) count()
C) size()
D) measure()
QCM - Java Collections (50 Questions)
29. Which collection is best for fast lookup?
A) ArrayList
B) HashSet
C) LinkedList
D) TreeSet
30. Comparable interface requires overriding:
A) compareTo()
B) equals()
C) hashCode()
D) toString()
31. Which class allows one null key?
A) TreeMap
B) HashMap
C) HashSet
D) LinkedList
32. Iterator has method to remove element during iteration?
A) delete()
B) remove()
C) eliminate()
D) discard()
33. Collections.reverse() works on:
A) Arrays only
B) Sets
C) Lists
D) Maps
34. Which is a legacy class?
A) ArrayList
B) Vector
QCM - Java Collections (50 Questions)
C) HashSet
D) TreeMap
35. The interface for sorted map is:
A) HashMap
B) TreeMap
C) LinkedHashMap
D) SortedMap
36. Which collection is thread-safe?
A) ArrayList
B) HashMap
C) Vector
D) HashSet
37. Which allows duplicate keys?
A) HashMap
B) TreeMap
C) Hashtable
D) None
38. Which allows duplicate values?
A) Set
B) Map
C) List
D) TreeSet
39. Which method returns first element of LinkedList?
A) first()
B) getFirst()
C) peek()
D) retrieve()
40. Which class automatically orders elements?
QCM - Java Collections (50 Questions)
A) HashSet
B) TreeSet
C) LinkedHashSet
D) HashMap
41. Which interface helps to iterate?
A) Comparable
B) Collection
C) Iterator
D) List
42. Which method of Iterator moves to next element?
A) move()
B) hasNext()
C) next()
D) step()
43. Collections.sort() can be applied to:
A) Maps
B) Lists
C) Sets
D) Arrays only
44. Which keyword is used in Generics?
A) T
B) V
C) E
D) All of these
45. Generics help in:
A) Runtime casting
B) Compile-time type checking
C) Memory allocation
QCM - Java Collections (50 Questions)
D) Performance slowing
46. What is the default initial capacity of ArrayList?
A) 5
B) 10
C) 15
D) 20
47. What happens if HashMap keys are not unique?
A) Error thrown
B) Last value replaces previous
C) Duplicates allowed
D) Runtime exception
48. Which Collection interface supports duplicate and null values?
A) List
B) Set
C) Map
D) Queue
49. Which structure uses buckets internally?
A) HashSet
B) ArrayList
C) LinkedList
D) Vector
50. Default sorting order is:
A) Descending
B) Ascending
C) Random
D) Insertion order