Shuffle Array Elements using Java

Collections.shuffle method

package app;

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

public class Main
{
    public static void main(String[] args)
    {
        Integer[] data = {10, 3, 17, 50, 15};
        List<Integer> list = Arrays.asList(data);
        Collections.shuffle(list);
        list.toArray(data);

        System.out.println(Arrays.toString(data));
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.