What is the difference between Vector and ArrayList in Java?

Java 8Object Oriented ProgrammingProgramming

ArrayList

 An array list is created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk.

Vector

Vector implements a dynamic array. It is similar to ArrayList, but with two differences −

  1. Vector is synchronized.
  2. The vector contains many legacy methods that are not part of the collections framework.

Vector proves to be very useful if you don't know the size of the array in advance or you just need one that can change sizes over the lifetime of a program.

raja
Published on 08-Feb-2018 13:13:11
Advertisements