Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vectors in Java

i recently started learning Java. I was studying Vectors and I came across various methods of declaring a Vector

Vector( )

Vector(int size)

Vector(int size, int incr)

Vector(Collection c)

I was able to understand the first two types but was not able to understand the increment type in 3rd type and what and when to use 4th type.

plz explain.

like image 382
Eljay Avatar asked Dec 09 '22 03:12

Eljay


1 Answers

You should use Vector(int size, int incr) when you want to control, what size for Vector will be set after it overflows.

You should use Vector(Collection c) when you want to fill it with values from another Collection.

Follow this link for further information.

Please note that in the most cases you should use ArrayList, not Vector. Vector has its method synchronized, you won't need that always.

like image 197
Artem Avatar answered Dec 11 '22 16:12

Artem