Topics Index

Collections Vector

If you need explanation Read this topic

If you need Answer Take test on this topic

Collections Vector
What will be the output of the following program?
import java.util.*;
public class VectorImplementation {
    public static void main(String[] args) {
        Vector vect = new Vector();
        vect.insertElementAt("Numbers In Words", 0);
        vect.insertElementAt("Four", 4);
        System.out.println("Size : " + vect.size());
        for (int i = 0; i < vect.size(); i++) {
            System.out.print(vect.elementAt(i) + " ");
        System.out.println("\nSize : " + vect.size());

A. Size : 4
One Two Three Four
Size : 4
[One, Two, Three, Four]
B. Size : 5
One Two Three Four Five 
Size : 4
[One, Two, Three, Four]
C. Size : 5
Numbers In Words One Two Three Four
Size : 5
[Numbers In Words, One, Two, Three, Four]
D. Size : 6
Numbers In Words One Two Three Four Five 
Size : 5
[Numbers In Words, One, Two, Three, Four]
E. Compilation Error Runtime Error
Topic: Java Vector

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is D part .........

Posted by Anuj Batham    2015-03-11 15:18:06

ans d.vector is dynamic array. Vector() Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.    boolean add (Object o) Appends the specified element to the end of this Vector .  in this program we appends 4 elements. thn    void insertElementAt (Object obj, int index) Inserts the specified object as a component in this vector at the specified index.2 elements get inserted into  0 and 4 th size 6,for loop prints 6 elements. thn   boolean removeElement (Object obj) Removes the first (lowest-indexed) occurrence of the argument from this vector.1 element get size is 5,thn sop prints vector elements

Posted by Maheshwari Natarajan    2015-03-11 18:49:47

This dose is now closed and the winners are Maheshwari Natarajan,  for 'First Correct Comment'. The 'lucky liker' is Kharag Konchok Tashi. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-03-12 02:12:12

© meritcampus 2019

All Rights Reserved.

Open In App