Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

270 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 191–200 of 270
Topics in Java Programming
Which of the following maintains insertion order in Java?
A HashSet
B TreeSet
C LinkedHashSet
D ConcurrentHashMap
Correct Answer:  C. LinkedHashSet
EXPLANATION

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.

Take Test
What is the underlying data structure of HashMap in Java?
A Balanced Binary Tree
B Hash Table with Buckets
C Linked List
D Array
Correct Answer:  B. Hash Table with Buckets
EXPLANATION

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.

Take Test
Which interface in Java Collections Framework does not allow duplicate elements?
A List
B Set
C Queue
D Map
Correct Answer:  B. Set
EXPLANATION

Set interface explicitly does not allow duplicate elements. List allows duplicates, Queue is for ordered collections, and Map stores key-value pairs.

Take Test
Which of the following correctly represents the hierarchy of Collection framework?
A Collection -> List -> Map -> Set
B Iterable -> Collection -> List/Set/Queue
C Object -> Iterable -> List -> Collection
D Map -> Collection -> List -> Set
Correct Answer:  B. Iterable -> Collection -> List/Set/Queue
EXPLANATION

The correct hierarchy is Iterable (interface) -> Collection -> List/Set/Queue/Deque interfaces.

Take Test
What does the poll() method return when called on an empty Queue?
A throws NoSuchElementException
B returns null
C returns empty object
D blocks indefinitely
Correct Answer:  B. returns null
EXPLANATION

poll() returns null if the queue is empty, while remove() throws NoSuchElementException.

Take Test
Which collection class is synchronized by default?
A HashMap
B ArrayList
C Hashtable
D TreeSet
Correct Answer:  C. Hashtable
EXPLANATION

Hashtable is a legacy synchronized collection class. HashMap, ArrayList, and TreeSet are not synchronized by default.

Take Test
What is the default initial capacity of a HashMap in Java?
A 8
B 16
C 32
D 64
Correct Answer:  B. 16
EXPLANATION

HashMap has a default initial capacity of 16 and a load factor of 0.75.

Take Test
Which of the following Collection interfaces does NOT support duplicate elements?
A Set
B List
C Queue
D Collection
Correct Answer:  A. Set
EXPLANATION

Set interface does not allow duplicate elements, while List, Queue, and Collection support duplicates.

Take Test
Which Collection method was introduced in Java 9 to create immutable collections?
A Collections.unmodifiableList()
B List.of()
C List.copyOf()
D Stream.collect()
Correct Answer:  B. List.of()
EXPLANATION

Java 9 introduced factory methods like List.of(), Set.of(), Map.of() for creating immutable collections.

Take Test
In the context of streams and collections, which method returns a Sequential Stream in Java 8+?
A collection.parallelStream()
B collection.stream()
C Stream.of(collection)
D collection.iterator().stream()
Correct Answer:  B. collection.stream()
EXPLANATION

collection.stream() returns a sequential stream, while parallelStream() returns a parallel stream.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips