how to shuffle an arraylist in java code example

Example: list shuffle java

import java.util.*;

public class List{
   
    public static void main(String[] args){
        LinkedList<Integer> ListOfNumbers = new LinkedList<Integer>();
        ListOfNumbers.add(1);
        ListOfNumbers.add(2);
        ListOfNumbers.add(3);
        ListOfNumbers.add(4);
        ListOfNumbers.add(5);
        System.out.println("The Original Sequence of numbers was : \n" + ListOfNumbers);
        Collections.shuffle(ListOfNumbers);
        System.out.println("\n The shuffled list is : \n" +ListOfNumbers );
    }
}

Tags:

Java Example