Which keyword is used to prevent a class from being subclassed in Java?
Answer: B
The 'final' keyword prevents a class from being extended. 'sealed' (Java 17+) allows selective subclassing, but 'final' is the standard way to prevent all subclassing.
Q.62Easy
Which interface does HashMap implement in Java Collections Framework?
Answer: A
HashMap implements the Map interface which stores key-value pairs. It does not implement Collection, List, or Set interfaces directly.
Q.63Easy
What is the time complexity of get() method in HashMap?
Answer: C
HashMap provides O(1) average time complexity for get() operation. In worst case with hash collisions, it can be O(n).
Q.64Easy
Which of the following collections maintains insertion order?
Answer: C
LinkedHashSet maintains insertion order using doubly-linked list. HashSet doesn't maintain order, TreeSet maintains sorted order, HashMap doesn't maintain insertion order.
Q.65Easy
What is the difference between ArrayList and LinkedList?
Answer: A
ArrayList is backed by a resizable array providing O(1) random access. LinkedList uses doubly-linked list providing O(1) insertion/deletion at ends but O(n) for random access.
Advertisement
Q.66Easy
Which collection does NOT allow duplicate elements?
Answer: B
Set interface implementations like HashSet do not allow duplicates. Lists (ArrayList, LinkedList, Vector) allow duplicates.
Q.67Easy
What is the difference between TreeSet and HashSet in sorting?
Answer: A
TreeSet maintains elements in sorted order using Red-Black tree. HashSet is unordered and uses hash table for storage.
Q.68Easy
Which method in Set collection prevents duplicate insertion by returning false?
Answer: A
The add() method in Set returns boolean - true if element is added, false if duplicate exists.
Q.69Easy
What is the output of LinkedHashMap iteration in the following code?
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
map.put("A", 1);
map.put("B", 2);
map.put("C", 3);
for(String key : map.keySet()) System.out.print(key);
Answer: A
LinkedHashMap maintains insertion order. Elements are iterated in the order they were inserted.
Q.70Easy
Which collection class implements NavigableMap interface?
Answer: B
TreeMap implements NavigableMap which provides methods like higherKey(), lowerKey(), floorEntry(), etc.
Q.71Easy
In the context of streams and collections, which method returns a Sequential Stream in Java 8+?
Answer: B
collection.stream() returns a sequential stream, while parallelStream() returns a parallel stream.
Q.72Easy
Which Collection method was introduced in Java 9 to create immutable collections?
Answer: B
Java 9 introduced factory methods like List.of(), Set.of(), Map.of() for creating immutable collections.
Q.73Easy
Which of the following Collection interfaces does NOT support duplicate elements?
Answer: A
Set interface does not allow duplicate elements, while List, Queue, and Collection support duplicates.
Q.74Easy
What is the default initial capacity of a HashMap in Java?
Answer: B
HashMap has a default initial capacity of 16 and a load factor of 0.75.
Q.75Easy
Which collection class is synchronized by default?
Answer: C
Hashtable is a legacy synchronized collection class. HashMap, ArrayList, and TreeSet are not synchronized by default.
Q.76Easy
What does the poll() method return when called on an empty Queue?
Answer: B
poll() returns null if the queue is empty, while remove() throws NoSuchElementException.
Q.77Easy
Which of the following correctly represents the hierarchy of Collection framework?
Answer: B
The correct hierarchy is Iterable (interface) -> Collection -> List/Set/Queue/Deque interfaces.
Q.78Easy
Which interface in Java Collections Framework does not allow duplicate elements?
Answer: B
Set interface explicitly does not allow duplicate elements. List allows duplicates, Queue is for ordered collections, and Map stores key-value pairs.
Q.79Easy
What is the underlying data structure of HashMap in Java?
Answer: B
HashMap uses a hash table with buckets (arrays of linked lists or red-black trees) to store key-value pairs for efficient O(1) average lookup time.
Q.80Easy
Which of the following maintains insertion order in Java?
Answer: C
LinkedHashSet maintains insertion order using a doubly-linked list. HashSet does not maintain order, TreeSet maintains sorted order, and ConcurrentHashMap doesn't guarantee insertion order.