0% found this document useful (0 votes)
24 views9 pages

Java Collections Framework Quiz

Its java Practice Test

Uploaded by

deeptasermaraj06
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)
24 views9 pages

Java Collections Framework Quiz

Its java Practice Test

Uploaded by

deeptasermaraj06
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

1.​ Which interface is the root of the Collections Framework?


a) Collection​
b) Collections​
c) Iterable​
d) List​

2.​ Which of the following allows duplicate elements?​


a) Set​
b) Map​
c) List​
d) None​

3.​ Which collection class does not maintain insertion order?​


a) ArrayList​
b) LinkedHashSet​
c) HashSet​
d) LinkedList​

4.​ Which of these allows you to store values of no fixed size?​


a) ArrayList​
b) All of these​
c) HashMap​
d) HashSet​

5.​ Which class implements a resizable array?​


a) Array​
b) ArrayList​
c) LinkedList​
d) Vector​

6.​ Which interface allows mapping keys to values?​


a) Set​
b) Map​
c) List​
d) Collection​

7.​ Which collection uses FIFO (First In First Out)?​


a) Stack​
b) Queue​
c) TreeSet​
d) LinkedHashMap​

8.​ Which collection uses LIFO (Last In First Out)?​


a) Stack​
b) Queue​
c) ArrayList​
d) TreeSet​

9.​ What is the initial capacity of an ArrayList if not specified?​


a) 5​
b) 8​
c) 10​
d) 16​

10.​Which collection sorts elements automatically?​


a) ArrayList​
b) HashSet​
c) TreeSet​
d) Vector​

11.​Which of these allows null keys?​


a) HashMap​
b) TreeMap​
c) Hashtable​
d) Both a and b​

12.​Which of these allows null values?​


a) HashMap​
b) TreeMap​
c) Hashtable​
d) Both a and b​

13.​Which of these is not part of the Collection interface?​


a) List​
b) Set​
c) Map​
d) Queue​

14.​Which method is used to sort a collection?​


a) [Link]()​
b) [Link]()​
c) [Link]()​
d) [Link]()​

15.​Which is faster for random access?​


a) ArrayList​
b) LinkedList​
c) Vector​
d) HashSet​

16.​Which maintains insertion order?​


a) HashSet​
b) LinkedHashSet​
c) TreeSet​
d) None​

17.​Which of this maintains insertion order and allow no duplicates ?​


a) LinkedHashMap​
b) ArrayList​
c) LinkedList​
d) HashSet​

18.​Which method removes all elements in a collection?​


a) delete()​
b) clear()​
c) removeAll()​
d) remove()​

19.​Which method starts a thread in Java?​


a) run()​
b) start()​
c) execute()​
d) begin()​

20.​Which interface must be implemented for a class to be executed by a thread?​


a) Runnable​
b) Threadable​
c) Executor​
d) Startable​

21.​Which interface does not extend Collection?​


a) Set​
b) List​
c) Queue​
d) Map​

22.​Which collection sorts based on keys?​


a) HashMap​
b) LinkedHashMap​
c) TreeMap​
d) Hashtable​

23.​Which method makes a thread pause temporarily without releasing the lock?​
a) wait()​
b) notify()​
c) sleep()​
d) yield()​
24.​Which thread state indicates that the thread has finished execution?​
a) New​
b) Runnable​
c) Terminated​
d) Waiting​

25.​Which method returns the number of elements in a collection?​


a) length()​
b) count()​
c) size()​
d) total()​

26.​Which concept allows only one thread to access a resource at a time?​


a) Multithreading​
b) Synchronization​
c) Deadlock​
d) Thread Pooling​

27.​Which collection allows duplicate keys?​


a) HashMap​
b) Hashtable​
c) TreeMap​
d) None​

28.​Which method is used to check if a collection is empty?​


a) isEmpty()​
b) empty()​
c) checkEmpty()​
d) null()​

29.​Which collection cannot store null elements?​


a) HashSet​
b) TreeSet​
c) ArrayList​
d) Vector​

30.​Which interface provides methods like add(), remove(), and contains()?​


a) Iterable​
b) Collection​
c) Map​
d) List​

Code based questions

1.​

List<Integer> list = new ArrayList<>();


for (int i = 1; i <= 5; i++) [Link](i * 2);
[Link](2);
[Link]([Link](2));

2.​

Set<String> set = new LinkedHashSet<>();


[Link]("B");
[Link]("A");
[Link]("C");
for (String s : set) [Link](s);

3.​

Map<Integer, String> map = new LinkedHashMap<>();


[Link](3, "X");
[Link](1, "Y");
[Link](2, "Z");
for (int k : [Link]()) [Link]([Link](k));
4.​

Queue<Integer> q = new PriorityQueue<>();


[Link](30); [Link](10); [Link](20);
[Link]([Link]() + " " + [Link]());

5.​

Stack<String> st = new Stack<>();


[Link]("A");
[Link]("B");
[Link]("C");
[Link]();
[Link]([Link]());

6.​

TreeSet<Integer> ts = new TreeSet<>();


[Link](50); [Link](10); [Link](30);
[Link]([Link](20));

7.​

LinkedList<Integer> ll = new LinkedList<>();


[Link](5); [Link](10); [Link](1, 7);
[Link](ll);

8.​

ArrayList<Integer> arr = new ArrayList<>([Link](1, 2, 3, 4));


[Link](2, 10);
[Link]([Link](10));
9.​

HashMap<String, Integer> hm = new HashMap<>();


[Link]("A", 1);
[Link]("B", 2);
[Link]("A", 3);
[Link]([Link]() + " " + [Link]("A"));

10.​

TreeMap<Integer, String> tm = new TreeMap<>();


[Link](2, "Two");
[Link](1, "One");
[Link](3, "Three");
[Link]([Link]() + " " + [Link]());

11.​

Vector<Integer> v = new Vector<>([Link](10, 20, 30));


[Link](1);
[Link](v);

12.​

List<String> l = new LinkedList<>([Link]("X", "Y", "Z"));


[Link]("Y");
[Link]([Link]("Z"));

13.​

HashSet<Integer> hs = new HashSet<>();


[Link](1); [Link](2); [Link](1);
[Link]([Link]());
14.​

List<Integer> l = [Link](1, 2, 3, 4, 5);


[Link]([Link](1, 4));

15.​

PriorityQueue<String> pq = new PriorityQueue<>();


[Link]("Banana");
[Link]("Apple");
[Link]("Cherry");
[Link]([Link]());

You might also like