Collections
- Which of these standard collection classes implements a linked list data structure?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
LinkedList
- If large number of items are stored in hash bucket, what happens to the internal structure?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
BalancedTree will improve performance from O(n) to O(log n) by reducing hash collisions.
- What is the output of below snippet?
import java.util.*;
public class Map_Example
{
public static void main(String[] args)
{
MapmapSample = new TreeMap ();
mapSample.put(4, null);
mapSample.put(0, null);
mapSample.put(3, null);
mapSample.put(2, null);
mapSample.put(1, null);
System.out.println(mapSample);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
HashMap needs unique keys. TreeMap sorts the keys while storing objects.
- How to externally synchronize hashmap?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Collections.synchronizedMap() synchronizes entire map. ConcurrentHashMap provides thread safety without synchronizing entire map.
- If two threads access the same hashmap at the same time, what would happen?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The code will throw ConcurrentModificationException if two threads access the same hashmap at the same time.