MCQ

Java MCQ – Collections – Part 4

This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Java Collections”.
 

1. HashTable internally uses the following technique for inserting and retrieving elements?

A Serialization

B Typecast

C Randomizing

D Hash

D
Hashtable internally uses the hash technique for inserting and retrieving elements.

 

 

2. Arraylist, Linkedlist and Vector are __________

A interfaces

B enums

C classes

D None of the above

C
Arraylist, Linkedlist, and vector are classes that implement the List interface.

 

 

3. Which of the following does not allow insertion of duplicates elements?

A Treeset

B Vector

C Linkedlist

D Copyonwritearraylist

A
Treeset is an implementation of Set, so it does not allow insertion of duplicates elements.

 

[st_adsense]  

4. Which gives better performance for inserting and deleting in the middle of the list?

A Vector

B ArrayList

C LinkedList

D All the answers are true

C
LinkedList offers better performance for inserting and deleting in the middle of a list.

 

 

5. What is the output of the following code?
import java.util.*;
	
public class Main 
{
	public static void main(String args[]) 
	{
		LinkedList<Integer> lang = new LinkedList<Integer>();
		lang.add(8);
		lang.add(2);
		lang.add(1);
		lang.add(6);

		Iterator it = lang.iterator();
		Collections.reverse(lang);
		Collections.sort(lang);
		while(it.hasNext())
			System.out.print(it.next() + " ");
	}
}

A 6 1 2 8

B 1 2 6 8

C 8 6 2 1

D 8 2 1 6

B

 

 

6. Which of these variables is a static variable defined in Collections?

A EMPTY_LIST

B EMPTY_SET

C EMPTY_MAP

D All the answers are true

D

 

 

7. After resizing, the size of the vector is increased by ___

A 200%

B 100%

C 50%

D None of the above

B

 

[st_adsense]  

8. After resizing, the size of the ArrayList is increased by ___

A 200%

B 100%

C 50%

D All the answers are true

C

 

 

9. Deque and Queue inherit from _____

A Collection

B AbstractList

C AbstractCollection

D List

A
Deque and Queue interfaces inherit from the Collection interface.

 

 

10. An unordered array has a search time complexity of ____

A O(log n)

B O(n)

C O(n + 1)

D O(1)

B

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More [st_adsense]

Leave a Reply

Your email address will not be published. Required fields are marked *