Java Program to Swap two Elements in a vector


-

-

Example:

Copied
import java.util.Collections;
import java.util.Vector;
public class VectorSwap {
	public static void main(String[] args) {
		Vector<String> vect = new Vector();
		vect.add("A1");
		vect.add("A2");
		vect.add("A3");
		vect.add("A4");
		vect.add("A5");
		System.out.println(vect);
		Collections.swap(vect, 0, 3);
		System.out.println("After swapping");
		System.out.println(vect);
	}
}

Output:

A1 A2 A3 A4 A5
After swapping
A4 A2 A3 A1 A5