MCQ

Java MCQ – Collections – Part 2

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

1. Collection ______________

A inherits the Collections class

B inherits the Iterable interface

C implements the Serializable interface

D implements the Traversable interface

B
Collection is an interface and inherits from the Iterable interface.

 

 

2. Which implementation of Iterator can traverse a collection back and forth?

A Iterator

B ListIterator

C SetIterator

D MapIterator

B
Iterator can only traverse forward while ListIterator traverses both forward and backward. ListIterator can help replace an element, while Iterator cannot.

 

 

3. The interface Comparable contains the method ___________

A toCompare

B compare

C compareTo

D compareWith

C
Comparable interface is used to classify objects of a user-defined class. This interface is in “java.lang” package and contains a single method named “compareTo(Object)”.

 

 

4. Collection is a(n) ____________

A interface

B class

C framework and interface

D framework and class

C
Collection is both a framework and an interface.

 

 

5. List, Set and Queue __________ Collection.

A inherit

B implement

C Both A and B are true

D None of the above

A
List, Set, and Queue are all interfaces and inherit from Collection interface.

 

 

6. Which of the following interfaces maintains the order in which the elements are inserted?

A Set

B List

C Map

D All the answers are true

B
List maintains the insertion order. In Set, only the LinkedHashSet implementation maintains the insertion order. In Map, LinkedHashMap maintains the insertion order.

 

 

7. Which of the following is an outdated class but still in use?

A Arraylist

B Vector

C Hashtable

D Both B and C are true.

D
Vector and Hashtable are outdated classes but still in use and currently not recommended for use.

 

 

8. Which of the following Sets maintains the insertion order?

A HashSet

B TreeSet

C LinkedHashSet

D All the answers are true

C
LinkedHashSet maintains the order in which the elements are inserted.

 

 

9. Which class stores elements in ascending order?

A ArrayList

B HashSet

C TreeSet

D All the answers are true

C
Treeset stores elements in ascending order by default.

 

 

10. Iterator and ListIterator can iterate through __________

A List

B Set

C Map

D All the answers are true

A
Iterator can be used to iterate through everything. ListIterator can only iterate through lists.

 

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

Leave a Reply

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