Vector.add(int index, E element) has the following syntax.
public void add(int index, E element)
In the following code shows how to use Vector.add(int index, E element) method.
/*from w w w . j av a2 s. c o m*/ import java.util.Vector; public class Main { public static void main(String[] args) { Vector<Integer> vec = new Vector<Integer> (4); vec.add(0,4); vec.add(1,3); vec.add(2,2); vec.add(3,1); for (Integer number : vec) { System.out.println("Index :"+vec.indexOf(number) +" Number: " + number); } // added new number 10 at 3rd position/index vec.add(3,10); for (Integer number : vec) { System.out.println("Index :"+vec.indexOf(number) +" Number: " + number); } } }
The code above generates the following result.