Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views3 pages

Framework

Uploaded by

aman00network
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)
6 views3 pages

Framework

Uploaded by

aman00network
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/ 3

Java Collection Framework Test

Section 1: Multiple Choice Questions (MCQs)

1. Which of the following is a part of the Java Collections Framework?


o a) Arrays
o b) HashMap
o c) File
o d) String
2. Which interface provides the basic methods for adding, removing, and querying
elements?
o a) List
o b) Set
o c) Collection
o d) Map
3. Which class implements the List interface and provides a resizable array?
o a) LinkedList
o b) ArrayList
o c) HashSet
o d) TreeMap
4. Which of the following is true about a Set in Java?
o a) It allows duplicate elements.
o b) It maintains the insertion order.
o c) It automatically sorts elements.
o d) It does not allow duplicate elements.
5. Which method is used to sort elements in a List?
o a) Collections.order()
o b) Collections.sort()
o c) List.sort()
o d) ArrayList.sort()
6. Which data structure does a TreeMap internally use?
o a) Hash table
o b) Binary search tree
o c) Red-Black tree
o d) B-tree
7. What is the default initial capacity of an ArrayList?
o a) 5
o b) 8
o c) 10
o d) 16
8. Which of the following classes does not allow null elements?
o a) ArrayList
o b) HashSet
o c) LinkedList
o d) TreeSet
9. Which method is used to check if a Map contains a specific key?
o a) containsValue()
o b) contains()
o c) containsKey()
o d) hasKey()
10. Which of the following statements is true for a PriorityQueue in Java?
o a) It maintains elements in natural order or according to a comparator.
o b) It allows duplicate elements.
o c) It allows null elements.
o d) It uses a hash table for internal storage.
11. Which collection class is synchronized?
o a) HashSet
o b) ArrayList
o c) Vector
o d) TreeSet

Section 2: True/False

13. The Collection interface extends the Map interface. (True/False)


14. A LinkedHashMap maintains the insertion order of its elements. (True/False)
15. The Queue interface is a subtype of the Collection interface. (True/False)
16. A TreeSet can contain duplicate elements. (True/False)
17. The ConcurrentModificationException is thrown when two threads modify
the same collection concurrently. (True/False)
18. A Deque can be used both as a stack and a queue. (True/False)

Section 3: Short Answer Questions

19. Explain the difference between HashSet and TreeSet.


20. What are the key differences betwe en an ArrayList and a LinkedList?
21. Describe how the equals() and hashCode() methods are related in the context
of the Java Collections Framework.

22. How does a WeakHashMap differ from a regular HashMap in Java?


23. Describe the behavior of the remove() method in a PriorityQueue.
24. What is the significance of the Comparator and Comparable interfaces in Java?
Section 4: Coding Questions
25. Write a Java program to remove duplicate elements from an ArrayList.

26. Write a Java code snippet to sort a Map by Customized sorting.


27. Write a Java code to convert Arraylist a synchronized list
28. Find the Most Frequent Element in an ArrayList
29. Write a Java method that merges two sorted LinkedLists into one
sorted LinkedList.
30. Reverse a LinkedList

31. Write a Java program to create a custom Comparator that sorts strings based
on their length.
Ans1:

32. Create a program that demonstrates the difference between peek(), poll(), and
remove() methods in a Queue.

33. Write code in java to explain Enumeration.

You might also like