Switch to Dark Mode

Java Collection Framework

Here are 10 essential multiple-choice questions on Java Collection Framework, covering key concepts


Last Updated : Apr 1, 2025
Discuss
Comments

Question 1

Which of the following is NOT a part of the Java Collection Framework?


  • A

    Map

  • B

    Queue

  • C

    Array

  • D

    Set

Question 2

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("A"); list.add("B"); list.add("C");
        Collections.reverse(list);
        System.out.println(list);
    }
}


  • A

    [A, B, C]


  • B

    [C, B, A]


  • C

    Compilation Error

  • D

    Runtime Error


Question 3

Which interface extends Collection but does NOT allow duplicate elements?


  • A

    List


  • B

    Queue

  • C

    Set

  • D

    Map

Question 4

Which method in the Collections class is used to make a collection immutable?

  • A

    Collections.lock()


  • B

    Collections.unmodifiableCollection()

  • C

    Collections.freeze()

  • D

    Collections.readOnlyCollection()

Question 5

What will happen if you try to add a null key in a HashMap?

  • A

    Throws NullPointerException

  • B

    Allowed only if the value is non-null

  • C

    Allowed, but only once

  • D

    Allowed multiple times

Question 6

Which of the following is true about LinkedHashSet?

  • A

    It allows duplicate elements

  • B

    It maintains insertion order

  • C

    It sorts elements in ascending order

  • D

    It does not use hashing

Question 7

What is the default capacity of ArrayList when using the no-arg constructor?


  • A

    0

  • B

    10

  • C

    16

  • D

    1

Question 8

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        Collections.fill(list, 5);
        System.out.println(list);
    }
}


  • A

    [1, 2, 3, 4]

  • B

    [5, 5, 5, 5]

  • C

    Compilation Error

  • D

    Runtime Error


Question 9

Which of the following Queue implementations provides thread-safe access?

  • A

    LinkedList

  • B

    PriorityQueue

  • C

    ArrayDeque

  • D

    ConcurrentLinkedQueue


Question 10

What is the key difference between Collection and Collections?

  • A

    Collection is a class, while Collections is an interface


  • B

    Collection is an interface, while Collections is a utility class


  • C

    Both are interfaces


  • D

    Both are utility classes

There are 10 questions to complete.

Take a part in the ongoing discussion