How to swap elements of Java Vector object using swap method of Collections class. - Java Collection Framework

Java examples for Collection Framework:Vector

Description

How to swap elements of Java Vector object using swap method of Collections class.

Demo Code


import java.util.Vector;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {
    Vector v = new Vector();

    v.add("1");/*from ww w. j a  va2  s.  co m*/
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");
   
    System.out.println("Before swaping, Vector contains : " + v);
   
    Collections.swap(v,0,4);
   
    System.out.println("After swaping, Vector contains : " + v);
   
  }
}

Result


Related Tutorials