Java Vector

Here are 10 essential multiple-choice questions on Java Vector, covering key concepts.

Last Updated :
Discuss
Comments

Question 1

Which package contains the Vector class in Java?


  • java.collection

  • java.util

  • java.list

  • java.vector

Question 2

How does Vector handle concurrent modifications?

  • It uses synchronized methods


  • It uses volatile keyword

  • It does not support concurrency

  • It throws ConcurrentModificationException

Question 3

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Vector<Integer> vector = new Vector<>(2);
        vector.add(10);
        vector.add(20);
        vector.add(30);
        System.out.println(vector.capacity());
    }
}


  • 2

  • 3

  • 4

  • 10

Question 4

Which method retrieves, but does not remove, the first element of a Vector?

  • peek()

  • firstElement()


  • head()

  • getFirst()

Question 5

What will be the output of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Vector<String> vector = new Vector<>();
        vector.add("A");
        vector.add("B");
        vector.add("C");
        vector.remove(1);
        System.out.println(vector);
    }
}


  • [A, C]

  • [B, C]


  • [A, B, C]


  • [A, C, B]



Question 6

What is the default initial capacity of a Vector in Java?

  • 5

  • 10

  • 15

  • 20

Question 7

Which of the following statements about Vector and ArrayList is true?


  • Vector is synchronized, whereas ArrayList is not


  • ArrayList is synchronized, whereas Vector is not


  • Both are synchronized

  • Neither is synchronized

Question 8

What will be the result of the following code?

Java
import java.util.*;
public class Test {
    public static void main(String[] args) {
        Vector<Integer> vector = new Vector<>();
        vector.add(5);
        vector.add(10);
        vector.add(15);
        System.out.println(vector.elementAt(2));
    }
}


  • 5

  • 10

  • 15

  • IndexOutOfBoundsException


Question 9

How does Vector differ from ArrayList when resizing?


  • Vector doubles its size, ArrayList increases by 50%

  • ArrayList doubles its size, Vector increases by 50%

  • Both increase their size by 50%

  • Both double their size

Question 10

Which method removes all elements from a Vector?


  • clear()

  • removeAll()

  • deleteAll()

  • flush()

There are 10 questions to complete.

Take a part in the ongoing discussion