Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

270 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 201–210 of 270
Topics in Java Programming
Which collection class implements NavigableMap interface?
A HashMap
B TreeMap
C LinkedHashMap
D EnumMap
Correct Answer:  B. TreeMap
EXPLANATION

TreeMap implements NavigableMap which provides methods like higherKey(), lowerKey(), floorEntry(), etc.

Take Test
What is the output of LinkedHashMap iteration in the following code?
LinkedHashMap map = new LinkedHashMap();
map.put("A", 1);
map.put("B", 2);
map.put("C", 3);
for(String key : map.keySet()) System.out.print(key);
A ABC
B CBA
C Random order
D BCA
Correct Answer:  A. ABC
EXPLANATION

LinkedHashMap maintains insertion order. Elements are iterated in the order they were inserted.

Take Test
Which method in Set collection prevents duplicate insertion by returning false?
A add()
B insert()
C put()
D append()
Correct Answer:  A. add()
EXPLANATION

The add() method in Set returns boolean - true if element is added, false if duplicate exists.

Take Test
What is the difference between TreeSet and HashSet in sorting?
A TreeSet is sorted, HashSet is unsorted
B HashSet is sorted, TreeSet is unsorted
C Both maintain same order
D Both are unsorted
Correct Answer:  A. TreeSet is sorted, HashSet is unsorted
EXPLANATION

TreeSet maintains elements in sorted order using Red-Black tree. HashSet is unordered and uses hash table for storage.

Take Test
Which collection does NOT allow duplicate elements?
A ArrayList
B HashSet
C LinkedList
D Vector
Correct Answer:  B. HashSet
EXPLANATION

Set interface implementations like HashSet do not allow duplicates. Lists (ArrayList, LinkedList, Vector) allow duplicates.

Take Test
What is the difference between ArrayList and LinkedList?
A ArrayList uses array, LinkedList uses linked list; ArrayList is faster for random access
B LinkedList uses array, ArrayList uses linked list
C Both use arrays internally
D ArrayList maintains insertion order, LinkedList doesn't
Correct Answer:  A. ArrayList uses array, LinkedList uses linked list; ArrayList is faster for random access
EXPLANATION

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.

Take Test
Which of the following collections maintains insertion order?
A HashSet
B TreeSet
C LinkedHashSet
D HashMap
Correct Answer:  C. LinkedHashSet
EXPLANATION

LinkedHashSet maintains insertion order using doubly-linked list. HashSet doesn't maintain order, TreeSet maintains sorted order, HashMap doesn't maintain insertion order.

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

HashMap provides O(1) average time complexity for get() operation. In worst case with hash collisions, it can be O(n).

Take Test
Which interface does HashMap implement in Java Collections Framework?
A Map interface
B Collection interface
C List interface
D Set interface
Correct Answer:  A. Map interface
EXPLANATION

HashMap implements the Map interface which stores key-value pairs. It does not implement Collection, List, or Set interfaces directly.

Take Test
Q.210 Easy OOP in Java
Which keyword is used to prevent a class from being subclassed in Java?
A abstract
B final
C static
D sealed
Correct Answer:  B. final
EXPLANATION

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.

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