Home Java Collection Generate shuffling in the specified list



Generate shuffling in the specified list
Posted on: September 1, 2008 at 12:00 AM
In this section we will learn how to generate shuffling in the specified list. When we will run this code output will be in random order.
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ListShuffling{
    public static void main(String args[]) {
        // create an array of employee names of string type.
        String employee[] = {"Mahendra", "Anu", "Sandeep", "Girish", "Komal"};
        // create list for the specified array of employee.
        List list1 = Arrays.asList(employee);
        // create object of Random class to generate number randomly.
        Random num = new Random();
        // shuffle and print the list according to the generated random number.
        Collections.shuffle(list1, num);
        System.out.println(list1);
    }
}


Related Tags for Generate shuffling in the specified list:
cdomliststaticrandomdiffiomethodsedoutputordercollectionrangethisidelementelementsifpublicietolearnvoidshuffleruncisheargenerateeilsectionliputusepeindifferentasstamntoutspecemoidmehowratedowhensspcolatishallcollecteaandarstatcodcodecollectufshufflingssrdrenthavstasisatihatfendodeonomolo


More Tutorials from this section

Ask Questions?    Discuss: Generate shuffling in the specified list  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.