0% found this document useful (0 votes)
49 views7 pages

Java Collections Framework 50 MCQs

The document contains 50 multiple-choice questions (MCQs) related to the Java Collections Framework, covering key concepts such as interfaces, classes, and methods. It includes questions about the main root interface, collection types, and their properties, as well as specific implementations like ArrayList, HashMap, and TreeSet. Each question is followed by the correct answer, providing a comprehensive overview of the Java Collections Framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views7 pages

Java Collections Framework 50 MCQs

The document contains 50 multiple-choice questions (MCQs) related to the Java Collections Framework, covering key concepts such as interfaces, classes, and methods. It includes questions about the main root interface, collection types, and their properties, as well as specific implementations like ArrayList, HashMap, and TreeSet. Each question is followed by the correct answer, providing a comprehensive overview of the Java Collections Framework.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Java Collections Framework – 50 MCQs with

Answers
1. What is the main root interface of the Collection Framework in Java?
A) List
B) Set
C) Collection
D) Map
Answer: C) Collection

2. Which of the following is not part of the Collection Framework?


A) List
B) Set
C) Map
D) Arrays
Answer: D) Arrays

3. Which interface provides a way to iterate elements one by one?


A) Enumeration
B) Iterator
C) Iterable
D) Comparator
Answer: B) Iterator

4. Which method is used to check if more elements exist while iterating?


A) hasNext()
B) next()
C) contains()
D) hasMoreElements()
Answer: A) hasNext()

5. Which of these is the parent interface of all collection classes?


A) Iterable
B) Iterator
C) Collection
D) Object
Answer: A) Iterable

6. The Collection Framework was introduced in which version of Java?


A) Java 1.1
B) Java 1.2
C) Java 1.3
D) Java 1.4
Answer: B) Java 1.2

7. Which of these interfaces is not part of the Collection hierarchy?


A) Queue
B) Deque
C) Map
D) SortedSet
Answer: C) Map

8. Which collection allows duplicate elements?


A) Set
B) Map
C) List
D) None
Answer: C) List

9. Which class provides a resizable array implementation?


A) LinkedList
B) ArrayList
C) HashSet
D) Vector
Answer: B) ArrayList

10. What is the default initial capacity of an ArrayList?


A) 5
B) 10
C) 15
D) 20
Answer: B) 10

11. Which is synchronized among these?


A) ArrayList
B) LinkedList
C) Vector
D) HashSet
Answer: C) Vector

12. Which class implements both List and Deque interfaces?


A) ArrayList
B) LinkedList
C) Stack
D) Vector
Answer: B) LinkedList

13. Which method adds an element to the end of an ArrayList?


A) append()
B) insert()
C) add()
D) push()
Answer: C) add()

14. Which method removes all elements from a Collection?


A) deleteAll()
B) removeAll()
C) clear()
D) empty()
Answer: C) clear()

15. Which collection class allows elements to be accessed in LIFO order?


A) Queue
B) Stack
C) Vector
D) LinkedList
Answer: B) Stack

16. Stack class extends which class?


A) ArrayList
B) LinkedList
C) Vector
D) Hashtable
Answer: C) Vector
17. Which interface supports FIFO order?
A) List
B) Queue
C) Stack
D) Set
Answer: B) Queue

18. Which queue class is implemented as a priority-based structure?


A) LinkedList
B) ArrayDeque
C) PriorityQueue
D) Stack
Answer: C) PriorityQueue

19. Which interface does Set extend?


A) Map
B) Collection
C) Queue
D) Iterable
Answer: B) Collection

20. Which Set implementation maintains insertion order?


A) HashSet
B) LinkedHashSet
C) TreeSet
D) SortedSet
Answer: B) LinkedHashSet

21. Which Set does not allow null elements and stores them in sorted order?
A) HashSet
B) LinkedHashSet
C) TreeSet
D) None
Answer: C) TreeSet

22. Which interface defines the ordering for a Set or Map?


A) SortedSet / SortedMap
B) Comparable
C) Comparator
D) Queue
Answer: A) SortedSet / SortedMap

23. Which Set class uses hashing for storage?


A) TreeSet
B) HashSet
C) LinkedHashSet
D) PriorityQueue
Answer: B) HashSet

24. Which method checks if a collection is empty?


A) isEmpty()
B) size() == 0
C) both A and B
D) contains()
Answer: C) both A and B

25. Which interface represents key-value pairs?


A) List
B) Set
C) Map
D) Queue
Answer: C) Map

26. Which Map class maintains insertion order?


A) HashMap
B) TreeMap
C) LinkedHashMap
D) Hashtable
Answer: C) LinkedHashMap

27. Which Map does not allow null key or value?


A) HashMap
B) TreeMap
C) Hashtable
D) LinkedHashMap
Answer: C) Hashtable

28. Which Map sorts keys in natural order?


A) LinkedHashMap
B) HashMap
C) TreeMap
D) Hashtable
Answer: C) TreeMap

29. Which class is legacy but synchronized and part of collection framework?
A) Vector
B) Hashtable
C) Stack
D) All of the above
Answer: D) All of the above

30. Which method retrieves a value from a Map using a key?


A) getValue()
B) fetch()
C) get()
D) find()
Answer: C) get()

31. Which method returns the Set of keys in a Map?


A) keySet()
B) getKeys()
C) entrySet()
D) values()
Answer: A) keySet()

32. Which method returns both key and value pairs?


A) keySet()
B) entrySet()
C) values()
D) getEntries()
Answer: B) entrySet()

33. What is the time complexity of HashMap get() in average case?


A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: A) O(1)

34. What is used to compare objects for natural ordering?


A) Comparator
B) Comparable
C) equals()
D) ==
Answer: B) Comparable

35. Which method must be implemented when using Comparable?


A) compare()
B) compareTo()
C) compareWith()
D) equals()
Answer: B) compareTo()

36. Which interface allows defining custom sorting?


A) Comparator
B) Comparable
C) Cloneable
D) Iterable
Answer: A) Comparator

37. Comparator interface defines which method?


A) compare()
B) compareTo()
C) equals()
D) sort()
Answer: A) compare()

38. Which class can be used to store configuration data like key=value pairs?
A) Map
B) Dictionary
C) Properties
D) HashMap
Answer: C) Properties

39. Properties class is a subclass of which class?


A) HashMap
B) Hashtable
C) TreeMap
D) Map
Answer: B) Hashtable

40. How are keys and values stored in Properties class?


A) String–String
B) Object–Object
C) Integer–String
D) String–Object
Answer: A) String–String

41. Which collection allows null key?


A) HashMap
B) Hashtable
C) TreeMap
D) None
Answer: A) HashMap
42. What happens if duplicate key is inserted in a Map?
A) Exception
B) Both stored
C) Old value replaced
D) Ignored
Answer: C) Old value replaced

43. Which among these provides constant-time performance for basic operations (add, remove,
contains)?
A) HashSet
B) TreeSet
C) LinkedHashSet
D) PriorityQueue
Answer: A) HashSet

44. Which Set implementation maintains elements in ascending order?


A) TreeSet
B) HashSet
C) LinkedHashSet
D) PriorityQueue
Answer: A) TreeSet

45. Which List implementation is best for frequent insertion/deletion?


A) ArrayList
B) LinkedList
C) Vector
D) Stack
Answer: B) LinkedList

46. Which List implementation is best for random access?


A) ArrayList
B) LinkedList
C) Vector
D) Stack
Answer: A) ArrayList

47. Which of these is true about Enumeration?


A) Introduced in Java 1.2
B) Can remove elements
C) Legacy interface
D) Faster than Iterator
Answer: C) Legacy interface

48. Which interface extends both Collection and Queue?


A) Deque
B) List
C) SortedSet
D) PriorityQueue
Answer: A) Deque

49. Which of the following is not synchronized?


A) Hashtable
B) Vector
C) HashMap
D) Stack
Answer: C) HashMap

50. Which statement about Collection Framework is true?


A) All collections are synchronized
B) Map extends Collection
C) Collections can be sorted using Collections.sort()
D) Collections cannot store null values
Answer: C) Collections can be sorted using Collections.sort()

You might also like