Saturday 18 February 2012

shuffle list elemnts


package com.usr.collections;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class ShuffleList {

       public static void main(String[] args) {
              String[] strArr = { "one", "two", "three", "four", "five", "six" };
              //converting to list
              List<String> strList = Arrays.asList(strArr);
              System.out.println("list elements are:" + strList);
              //public static void shuffle(List<?> list) method shuffles elements of the provided LIst
              Collections.shuffle(strList);
              System.out.println("list elements after shuffling are:" + strList);
       }

}

output 
list elements are:[one, two, three, four, five, six]
list elements after shuffling are:[six, three, five, four, two, one]

No comments:

Post a Comment

Note: only a member of this blog may post a comment.