Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 701–710 of 958
Topics in Java Programming
What is the difference between ArrayList and Vector?
A ArrayList is synchronized, Vector is not
B Vector is synchronized, ArrayList is not
C Both are synchronized
D Neither is synchronized
Correct Answer:  B. Vector is synchronized, ArrayList is not
EXPLANATION

Vector is a legacy synchronized collection, while ArrayList is unsynchronized but faster. For thread-safety with ArrayList, use Collections.synchronizedList().

Take Test
What is the time complexity of get() operation in TreeMap?
A O(1)
B O(log n)
C O(n)
D O(n log n)
Correct Answer:  B. O(log n)
EXPLANATION

TreeMap is based on Red-Black tree, so get(), put(), and remove() operations have O(log n) time complexity due to tree traversal.

Take Test
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
What does the spliterator() method introduced in Java 8 provide over Iterator?
A Better support for parallel processing
B Faster sequential iteration
C Backward iteration capability
D Automatic synchronization
Correct Answer:  A. Better support for parallel processing
EXPLANATION

Spliterator provides split() capability enabling efficient parallel stream processing with characteristics advertisement.

Take Test
In a scenario where you need to maintain a mapping with LRU (Least Recently Used) eviction policy, which class should be extended?
A LinkedHashMap with override of removeEldestEntry()
B TreeMap
C WeakHashMap
D ConcurrentHashMap
Correct Answer:  A. LinkedHashMap with override of removeEldestEntry()
EXPLANATION

LinkedHashMap can be extended and removeEldestEntry() overridden to implement LRU cache eviction policy.

Take Test
What is the worst-case time complexity of QuickSort when used with Collections.sort()?
A O(n log n)
B O(n²)
C O(n)
D O(log n)
Correct Answer:  B. O(n²)
EXPLANATION

Collections.sort() uses TimSort (hybrid of merge and insertion sort) with O(n log n) worst-case, but QuickSort's worst-case is O(n²).

Take Test
Which stream terminal operation preserves encounter order in parallel streams for Collections?
A collect() with unordered Collector
B collect() with CONCURRENT and UNORDERED characteristics
C forEach() directly
D forEachOrdered()
Correct Answer:  D. forEachOrdered()
EXPLANATION

forEachOrdered() preserves encounter order even in parallel streams, while forEach() doesn't guarantee order.

Take Test
What is the time complexity of subList() operation in ArrayList?
A O(1) - returns a view
B O(n) - creates a copy
C O(log n)
D O(n log n)
Correct Answer:  A. O(1) - returns a view
EXPLANATION

subList() returns a view (structural reference) to the original list in O(1) time, not a copy.

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