Collections


  1. Which of these class object uses the key to store value?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Dictionary, Map & Hashtable all implement Map interface hence all of them uses keys to store value in the object.


  1. What is the output of this program?
    import java.util.*;
    public class stack_Example
    {
    public static void main(String args[])
    {
    Stack object = new Stack();
    object.push(new Integer(20));
    object.push(new Integer(12));
    object.pop();
    object.push(new Integer(60));
    System.out.println(object);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    push() and pop() are standard functions of the class stack, push() inserts in the stack and pop removes from the stack. 20 & 12 are inserted using push() the pop() is used which removes 12 from the stack then again push is used to insert 60 hence stack contains elements 20 & 60.



  1. What is the output of this program?
    import java.util.*;
    public class vector_Example
    {
    public static void main(String args[])
    {
    Vector object = new Vector(6,3);
    object.addElement(new Integer(10));
    object.addElement(new Integer(20));
    object.addElement(new Integer(50));
    object.removeAll(object);
    System.out.println(object.isEmpty());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    firstly elements 10, 20, 50 are entered in the vector object, but when object.removeAll(object); is executed all the elements are deleted and vector is empty, hence object.isEmpty() returns true.


  1. What is the output of this program?
    import java.util.*;
    public class vector_Example
    {
    public static void main(String args[])
    {
    Vector object = new Vector(6,3);
    object.addElement(new Integer(10));
    object.addElement(new Integer(20));
    object.addElement(new Integer(60));
    object.insertElementAt(new Integer(80), 1);
    System.out.println(object);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    [10, 80, 20, 60]



  1. What is the output of this program?
    import java.util.*;
    public class vector
    {
    public static void main(String args[])
    {
    Vector object = new Vector(6,3);
    object.addElement(new Integer(9));
    object.addElement(new Integer(7));
    object.addElement(new Integer(3));
    System.out.println(object.capacity());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    6