Vidyalelo
Java Programming · all questions

Java Collections Framework
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

179

Questions

5/9

Page

Pick an option on a question to see the right answer and solution.

Which of these class is used for creating a client for a server-client operations?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class Array
{
    public static void main(String args[]) 
    {
        int array[] = new int [5];
        for (int i = 5; i > 0; i--)
            array[5 - i] = i;
        Arrays.sort(array);
        for (int i = 0; i < 5; ++i)
          System.out.print(array[i]);;
    }
}

Select an option to see the answer and solution.

What is the unique feature of LinkedHashSet?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class Arraylist 
{
    public static void main(String args[])
    {
        ArrayList obj1 = new ArrayList();
        ArrayList obj2 = new ArrayList();
        obj1.add("A");
        obj1.add("B");
        obj2.add("A");
        obj2.add(1, "B");
        System.out.println(obj1.equals(obj2));
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class Maps 
{
    public static void main(String args[]) 
    {
        HashMap obj = new HashMap();
        obj.put("A", new Integer(1));
        obj.put("B", new Integer(2));
        obj.put("C", new Integer(3));
        System.out.println(obj);
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of these class object can be used to form a dynamic array?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class Collection_Algos 
{
    public static void main(String args[]) 
    {
        LinkedList list = new LinkedList();
        list.add(new Integer(2));
        list.add(new Integer(8));
        list.add(new Integer(5));
        list.add(new Integer(1));
        Iterator i = list.iterator();
        Collections.reverse(list);
  while(i.hasNext())
      System.out.print(i.next() + " ");
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
import java.util.*;
class vector 
{
    public static void main(String args[]) 
    {
        Vector obj = new Vector(4,2);
        obj.addElement(new Integer(3));
        obj.addElement(new Integer(2));
        obj.addElement(new Integer(5));
        System.out.println(obj.elementAt(1));
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
import java.util.*;
class stack 
{
    public static void main(String args[]) 
    {
        Stack obj = new Stack();
        obj.push(new Integer(3));
        obj.push(new Integer(2));
        obj.pop();
        obj.push(new Integer(5));
      System.out.println(obj);
    }
}

Select an option to see the answer and solution.

Which of these methods can randomize all elements in a list?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of these methods can be used to obtain a static array from an ArrayList object?

Select an option to see the answer and solution.

Which of these method is used to insert value and its key?

Select an option to see the answer and solution.

Which of these method is used to remove all keys/values pair from the invoking map?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class Collection_iterators 
{
    public static void main(String args[]) 
    {
        ListIterator a = list.listIterator();
            if(a.previousIndex()! = -1)
                while(a.hasNext())
              System.out.print(a.next() + " ");
            else
               System.out.print("EMPTY");
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.lang.reflect.*;
class Additional_packages
{	 
     public static void main(String args[])
     {
   try
         {
       Class c = Class.forName("java.awt.Dimension");
 Method methods[] = c.getMethods();
 for (int i = 0; i < methods.length; i++)
     System.out.println(methods[i]);
   }
   catch (Exception e)
         {
         System.out.print("Exception");
         }
    }
}

Select an option to see the answer and solution.

What happens if we put a key object in a HashMap which exists?

Select an option to see the answer and solution.

Which of these interface handle sequences?

Select an option to see the answer and solution.

How to externally synchronize hashmap?

Select an option to see the answer and solution.