Shuffle elements of Vector - Java Collection Framework

Java examples for Collection Framework:Vector

Introduction

To shuffle elements of Vector use static void shuffle(List list) 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();
   /*from  w  w  w  .j av  a2  s  .com*/
    v.add("1");
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");
   
    System.out.println("Before shuffling, Vector contains : " + v);

    Collections.shuffle(v);
   
    System.out.println("After shuffling, Vector contains : " + v);
   
  }
}

Result


Related Tutorials