0% found this document useful (0 votes)
15 views7 pages

Collections

The document contains a series of multiple-choice questions related to Java Collections Framework, covering topics such as interfaces, classes, methods, and their functionalities. It addresses concepts like the behavior of different collection types, time complexities, and specific methods used within these collections. The questions are designed to test knowledge on Java data structures, their properties, and usage.
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)
15 views7 pages

Collections

The document contains a series of multiple-choice questions related to Java Collections Framework, covering topics such as interfaces, classes, methods, and their functionalities. It addresses concepts like the behavior of different collection types, time complexities, and specific methods used within these collections. The questions are designed to test knowledge on Java data structures, their properties, and usage.
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/ 7

• Which of the following interfaces does the Set interface extend?

• A) Collection
• B) List
• C) Map
• D) None of the above
• Which of these is not a part of the Java Collection Framework?
• A) HashMap
• B) Dictionary
• C) ArrayList
• D) HashSet
• Which class provides a dynamic array in Java?
• A) ArrayList
• B) HashSet
• C) Vector
• D) LinkedList
• What does the java.util.Collections class provide?

• A) Collection classes
• B) Methods to manipulate collections
• C) A framework for Collection classes
• D) A collection of collections
• Which of the following allows duplicate elements?
• A) Set
• B) List
• C) Map
• D) None of the above
• Which interface provides the functionality to store unique elements only?
• A) List
• B) Set
• C) Map
• D) Collection
• Which method is used to add an element to a collection?
• A) add()
• B) insert()
• C) put()
• D) append()
• Which of these classes implements the List interface?

• A) HashMap
• B) TreeSet
• C) LinkedList
• D) TreeMap
• The LinkedList class in Java uses which data structure?

• A) Array
• B) Hash table
• C) Linked list
• D) Binary tree
• Which of these collections uses a hashing mechanism to store elements?
• A) LinkedList
• B) HashSet
• C) ArrayList
• D) TreeSet
• The HashMap class implements which of these interfaces?

• A) Map
• B) Set
• C) List
• D) Collection
• Which class provides constant time for basic operations like add, remove, contains, and
size?
• A) ArrayList
• B) LinkedList
• C) HashSet
• D) TreeMap
• What is the output of new TreeSet<>(Arrays.asList(3, 2, 1, 4))?

• A) [4, 3, 2, 1]
• B) [1, 2, 3, 4]
• C) [1, 3, 2, 4]
• D) Random order
• Which of these collections is synchronized?
• A) ArrayList
• B) HashMap
• C) TreeMap
• D) Vector
• Which collection class does not allow null values?
• A) LinkedList
• B) HashMap
• C) TreeMap
• D) HashSet
• What is the default load factor of a HashMap?
• A) 0.25
• B) 0.50
• C) 0.75
• D) 1.00
• Which method returns the number of elements in a collection?
• A) size()
• B) length()
• C) count()
• D) getSize()
• Which of these methods is used to obtain an iterator?
• A) getIterator()
• B) iterator()
• C) iter()
• D) retrieve()
• Which collection supports the LIFO order?
• A) ArrayList
• B) LinkedList
• C) Stack
• D) HashSet
• Which data structure is best for fast searches?
• A) ArrayList
• B) LinkedList
• C) HashMap
• D) TreeSet
• The Queue interface is implemented by which of the following classes?
• A) Stack
• B) ArrayDeque
• C) LinkedList
• D) Both B and C
• Which of these classes is generally preferred for implementing the Map interface?
• A) HashMap
• B) HashSet
• C) ArrayList
• D) Vector
• Which method removes the first occurrence of an element in a list?
• A) remove()
• B) removeFirst()
• C) delete()
• D) deleteFirst()
• Which interface provides sorting of elements in natural order?
• A) Comparable
• B) Comparator
• C) Both A and B
• D) None of the above
• Which of these classes provides better search performance?
• A) LinkedList
• B) ArrayList
• C) Vector
• D) HashSet
• What is the time complexity of searching in a HashMap?

• A) O(n)
• B) O(log n)
• C) O(1)
• D) O(n log n)
• Which method in Map interface is used to obtain a collection view of the values?

• A) values()
• B) viewValues()
• C) getValues()
• D) retrieveValues()
• Which collection supports FIFO order?
• A) Stack
• B) Queue
• C) LinkedList
• D) ArrayList
• Which class implements both List and Deque interfaces?
• A) LinkedList
• B) ArrayList
• C) HashSet
• D) HashMap
• In TreeMap, elements are stored in:

• A) Random order
• B) Descending order
• C) Natural order
• D) Insertion order
• Which method removes all elements from a collection?
• A) removeAll()
• B) deleteAll()
• C) clear()
• D) purge()
• HashSet is implemented using which data structure?

• A) Array
• B) Linked list
• C) Hash table
• D) Binary tree
• Which class maintains insertion order?
• A) HashMap
• B) TreeMap
• C) LinkedHashMap
• D) HashSet
• Which method is used to retrieve, but not remove, the head of a queue?
• A) head()
• B) peek()
• C) poll()
• D) element()
• Which of the following collections doesn’t allow duplicate values?
• A) List
• B) Map
• C) Set
• D) Collection
• What is the time complexity of contains method in a HashSet?

• A) O(1)
• B) O(log n)
• C) O(n)
• D) O(n log n)
• The Collections.max() method returns:

• A) Maximum element
• B) Minimum element
• C) Median element
• D) None of the above
• Which of the following classes can store null values?

• A) HashMap
• B) TreeMap
• C) TreeSet
• D) All of the above
• Which interface provides the method put?

• A) Collection
• B) Set
• C) Map
• D) List
• In Java Collections, the term fail-fast refers to:

• A) Concurrent modification detection


• B) Fast insertion of elements
• C) Fast deletion of elements
• D) None of the above
• Which class provides a scalable and synchronized implementation of Map?

• A) TreeMap
• B) HashMap
• C) ConcurrentHashMap
• D) Hashtable
• The Collections.shuffle() method is used to:

• A) Sort elements
• B) Randomize elements
• C) Find max element
• D) Find min element
• Which class provides support for blocking queues?

• A) Queue
• B) BlockingQueue
• C) ArrayList
• D) LinkedList
• Which method retrieves and removes the head of the queue?
• A) peek()
• B) poll()
• C) remove()
• D) element()
• Which class does not support null values?

• A) LinkedList
• B) HashSet
• C) TreeSet
• D) ArrayList
• Which collection maintains a sorted order of elements?
• A) HashSet
• B) TreeSet
• C) ArrayList
• D) LinkedHashSet
• Which method checks if a collection is empty?
• A) isEmpty()
• B) empty()
• C) hasNoElements()
• D) checkEmpty()
• The remove method throws NoSuchElementException if:

• A) The list is empty


• B) The element is not found
• C) The element has duplicates
• D) The element

You might also like