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

8/9

Page

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

What will be the output of the following Java code?
import java.util.*;
class Bitset 
{
    public static void main(String args[])
    {
        BitSet obj = new BitSet(5);
        for (int i = 0; i < 5; ++i)
            obj.set(i);
        obj.clear(2);
        System.out.print(obj.length() + " " + obj.size());
    }
}

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.

Which of these methods can be used to move to next element in a collection?

Select an option to see the answer and solution.

Which of this method is used to change an element in a LinkedList Object?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.util.*;
class Linkedlist 
{
    public static void main(String args[]) 
    {
        LinkedList obj = new LinkedList();
        obj.add("A");
        obj.add("B");
        obj.add("C");
        obj.removeFirst();
        System.out.println(obj);
    }
}

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));
        obj.removeAll(obj);
        System.out.println(obj.isEmpty());
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java code?
import java.util.*;
class hashtable 
{
    public static void main(String args[]) 
    {
        Hashtable obj = new Hashtable();
        obj.put("A", new Integer(3));
        obj.put("B", new Integer(2));
        obj.put("C", new Integer(8));
        obj.remove(new String("A"));
        System.out.print(obj);
    }
}

Select an option to see the answer and solution.

Which of these classes implements Set interface?

Select an option to see the answer and solution.

Which of this interface is not a part of Java's collection framework?

Select an option to see the answer and solution.

Which of this method is used to make all elements of an equal to specified value?

Select an option to see the answer and solution.

Which of these interface declares core method that all collections will have?

Select an option to see the answer and solution.

What is the difference between TreeSet and SortedSet?

Select an option to see the answer and solution.

Map implements collection interface?

Select an option to see the answer and solution.

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

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);
  Collections.shuffle(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(6));
        obj.insertElementAt(new Integer(8), 2);
        System.out.println(obj);
    }
}

Select an option to see the answer and solution.

Which of these methods sets every element of a List to a specified object?

Select an option to see the answer and solution.

Which of these methods can be used to delete the last element in a LinkedList object?

Select an option to see the answer and solution.

Which of these method is used to add an element to the start of a LinkedList object?

Select an option to see the answer and solution.

What will be the output of the following Java code?
import java.util.*;
class properties 
{
    public static void main(String args[]) 
    {
        Properties obj = new Properties();
        obj.put("AB", new Integer(3));
        obj.put("BC", new Integer(2));
        obj.put("CD", new Integer(8));
        System.out.print(obj.keySet());
    }
}

Select an option to see the answer and solution.