I have a method which needs to return a Vector object. Now, I realize that I dont really need it to be a Vector here and an ArrayList would do the job too since i dont need a synchronized collection. However, due to framework limitations, the return type must be a vector.
I was wondering if I could improve performance if I add objects to an ArrayList, and convert it into a Vector by doing something like
List list = new ArrayList();
return new Vector(list);
Or would simply adding objects to a Vector be better than doing the above/
The difference is likely to be very small. Using a Vector is not ideal but unlikely to make much difference.
When you create a Vector from a List it has to add all the elements anyway so creating an ArrayList first doesn't save anything.