Java Collections MCQ - Multiple Choice Questions And Answers
Q. What is the difference between a List and a Set in Java Collections?
A. A List allows duplicate elements, while a Set does notB. A List does not allow duplicate elements, while a Set does
C. A List is ordered, while a Set is not
D. A List is not ordered, while a Set is
Q. Which Java Collection class provides a key-value mapping?
A. ListB. Set
C. Map
D. Queue
Q. Which Java Collection class allows null elements?
A. ListB. Set
C. Map
D. Queue
Q. Which Java Collection class provides a LIFO (Last-In-First-Out) ordering?
A. ListB. Set
C. Map
D. Queue
Q. Which Java Collection class maintains the insertion order?
A. ListB. Set
C. Map
D. Queue
Q. Which Java Collection class provides a sorted order?
A. ListB. Set
C. Map
D. Queue
Q. Which Java Collection class provides a First-In-First-Out (FIFO) ordering?
A. ListB. Set
C. Map
D. Queue
Q. What is the purpose of the Comparator interface in Java Collections?
A. To provide a default ordering of elementsB. To define custom sorting logic
C. To filter elements based on a condition
D. To transform values
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values
Q. Which Java Collection class provides a resizable array?
A. ListB. Set
C. Map
D. Queue
Q. What is the correct way to create an ArrayList in Java?
A.ArrayList<String> list = new ArrayList<>();B.
ArrayList list = new ArrayList();C.
ArrayList<String> list = new ArrayList<String>();D.
ArrayList<String> list = new ArrayList<String>;
Q. What is the difference between ArrayList and LinkedList in Java?
A.ArrayList is an ordered collection while LinkedList is an unordered collection.B.
ArrayList is faster for insertion and removal operations while LinkedList is faster for random access operations.C.
ArrayList uses a doubly linked list data structure while LinkedList uses an array data structure.D.
There is no difference between ArrayList and LinkedList in Java.