3

In an interview I was being asked by two questions that are..

When does practically we require the use of vector..? As per my analysis synchronization is the main reason but they were intrested to know that apart from synchronization what are the other practical reasons that we may prefer the use of vector.

Please advise that apart from synchronization what are the other various reason that we will choose vector legacy collection..!

user1633823
  • 347
  • 2
  • 5
  • 14

2 Answers2

0

One difference I can think of is Vector supports Enumeration.You can get create Enumeration easily by calling

Enumeration enums  = v.elements();

But in case of ArrayList,you need to do like this:

Enumeration enums = Collections.enumeration(arrayList);
UVM
  • 9,776
  • 6
  • 41
  • 66
0

Vectors are used in the variable length argument in java.because Vector can automatically expand based on the argument passed to it.

for example

public int sum(int i...)
{ 
    int sum=0;
    for(int s:i)
    {
    sum=sum+s;
    }
    return sum;
}

in this method I have passed i as an variable length argument no matter how many integer the user will pass to this method ,this method will return the sum based on the user arguments..

so vector provides this facility to the user.

this is where vectors are implemented.Internally the variable length arguments uses Vector to store the Data.

kTiwari
  • 1,488
  • 1
  • 14
  • 21