Collections


  1. Which of these standard collection classes implements a linked list data structure?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    LinkedList


  1. If large number of items are stored in hash bucket, what happens to the internal structure?











  1. 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.



  1. What is the output of below snippet?
    import java.util.*;
    public class Map_Example
    {
    public static void main(String[] args)
    {
    Map mapSample = 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);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    HashMap needs unique keys. TreeMap sorts the keys while storing objects.


  1. How to externally synchronize hashmap?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Collections.synchronizedMap() synchronizes entire map. ConcurrentHashMap provides thread safety without synchronizing entire map.



  1. If two threads access the same hashmap at the same time, what would happen?











  1. 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.