
How can we use the vector class in java program?

The vector class is similar to the ArrayList class except that the vector class is synchronized.
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
public class VectorExample{
public static void main(String [] args){
List vector = new Vector();
vector.add("Apple");
vector.add("Orange");
vector.add("Grapes");
vector.add("Pine");
vector.add( "89");
vector.add('A');
vector.add(25);
vector.remove("89");
Iterator it = vector.iterator();
while(it.hasNext())
System.out.println(it.next());
}
}
Output:
Apple Orange Grapes Pine A 25
Description:- The above program demonstrates the concept of List interface. Here we have created an object of Vector class and add elements to the vector. Then we have removed an element â??89â?? using remove() method from the Vector and iterated the remaining elements of vector using Iterator and display them.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.