Collections


  1. Which of these object stores association between keys and values?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Map


  1. What is the output of this program?
    import java.util.*; 
    public class TreeSet_Example
    {
    public static void main(String args[])
    {
    TreeSet object = new TreeSet();
    object.add("7");
    object.add("0");
    object.add("9");
    object.add("5");
    object.add("6");
    System.out.println(object);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    TreeSet class uses set to store the values added by function add in ascending order using tree for storage



  1. What is the output of this program?
    import java.util.*;
    public class HashSet_Example
    {
    public static void main(String args[])
    {
    HashSet object = new HashSet();
    object.add("I");
    object.add("L");
    object.add("U");
    System.out.println(object + " " + object.size());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    HashSet obj creates an hash object which implements Set interface, object.size() gives the number of elements stored in the object object which in this case is 3.


  1. What is the output of this program?
    import java.util.*;
    public class Linkedlist_Example
    {
    public static void main(String args[])
    {
    LinkedList object = new LinkedList();
    object.add("I");
    object.add("L");
    object.add("U");
    object.removeFirst();
    System.out.println(object);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    [L, U]



  1. What is the output of this program?
    import java.util.*;
    public class Linkedlist_Example
    {
    public static void main(String args[])
    {
    LinkedList object = new LinkedList();
    object.add("O");
    object.add("V");
    object.add("E");
    object.addFirst("L");
    System.out.println(object);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    object.addFirst(“L”) method is used to add ‘L’ to the start of a LinkedList object obj.