java.util.Vector Example in Java
September 27, 2013
java.util.Vector has been introduced in JDK 1.1. Vector works same like ArrayList. Vector will grow automatically when we keep on adding elements. Vector is synchronized and thread safe. If we remove the elements from the vector, it will shrink the size automatically. Find the sample example.
VectorTest.java
package com.concretepage.util; import java.util.Vector; public class VectorTest { public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("A"); v.add("B"); v.add("C"); v.add("D"); for(String s: v){ System.out.println(s); } System.out.println("Checks availability of element by contains method"); System.out.println(v.contains("A")); System.out.println("Remove element by remove method."); //remove first element v.remove(0); for(String s: v){ System.out.println(s); } } }
A B C D Checks availability of element by contains method true Remove element by remove method. B C D