Wednesday 1 July 2015

Java : Collection Framework : Collections (Shuffle)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=3P4Av4gx0JU&list=UUhwKlOVR041tngjerWxVccw

CollectionsExample.java
import java.util.ArrayList;
import java.util.Collections;

/*
 Method: 

 public static void shuffle(List<?> list)

 Parameters:

 list - the list to be shuffled.

 */

public class CollectionsExample
{

    public static void main(String[] args)
    {

        ArrayList<Integer> arrayList = new ArrayList<Integer>();

        arrayList.add(1000);
        arrayList.add(2000);
        arrayList.add(3000);
        arrayList.add(4000);
        arrayList.add(5000);

        System.out.println("Before shuffle , arrayList : " + arrayList + "\n");

        /*
         * Randomly permutes the specified list using a default source of
         * randomness.
         */
        Collections.shuffle(arrayList);

        System.out.println("After shuffle , arrayList : " + arrayList + "\n");

    }

}
Output
Before shuffle , arrayList : [1000, 2000, 3000, 4000, 5000]

After shuffle , arrayList : [5000, 2000, 1000, 3000, 4000]
To Download CollectionsDemoShuffleApp Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/CollectionsDemoShuffleApp.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment