examples of vector in java programming

0

Vector:

It is the same as Array List.

  • Vector methods are synchronized.
  • Thread safety.
  • It also implements Random Access.
  • Thread safety usually causes a performance hit.

Example:

public class Fruit {
public static void main (String [ ] args){
Vector <String> names = new Vector <String> ( );
 names.add (“cherry”);
names.add (“apple”);
names.add (“banana”);
names.add (“kiwi”);
names.add (“apple”);
System.out.println (“names”);
}
}

Output:

[cherry,apple,banana,kiwi,apple]

Vector also maintains the insertion order and accepts the duplicates.

All Contributions

total contributions (0)

New to examplegeek.com?

Join us