import java.util.*;
public class GFG {
public static void main(String args[])
{
// creating an instance of LinkedList
LinkedList
Java
import java.util.Collections;
import java.util.LinkedList;
public class GFG {
public static void main(String args[])
{
// Creating a LinkedList
LinkedList list = new LinkedList<>();
list.add(45);
list.add("GFG");
list.add(2.56f);
list.add(965.321);
list.add('A');
list.add(true);
System.out.println(
"The LinkedList before shuffle : "
+ list.toString());
System.out.println();
// here we are shuffling more than once
// shuffle 1
Collections.shuffle(list);
System.out.println(
"The LinkedList after shuffle 1 : "
+ list.toString());
System.out.println();
// shuffle 2
Collections.shuffle(list);
System.out.println(
"The LinkedList after shuffle 2 : "
+ list.toString());
System.out.println();
// shuffle 3
Collections.shuffle(list);
System.out.println(
"The LinkedList after shuffle 3 : "
+ list.toString());
}
}
输出
The list before shuffle : [45, GFG, 2.56, 965.321, A, true]
The list after shuffle 1 : [965.321, 2.56, GFG, 45, A, true]
The list after shuffle 2 : [965.321, 45, A, 2.56, GFG, true]
The list after shuffle 3 : [965.321, 45, GFG, 2.56, A, true]
import java.util.Collections;
import java.util.LinkedList;
public class GFG {
public static void main(String args[])
{
// Creating a LinkedList
LinkedList list = new LinkedList<>();
list.add(45);
list.add("GFG");
list.add(2.56f);
list.add(965.321);
list.add('A');
list.add(true);
System.out.println(
"The LinkedList before shuffle : "
+ list.toString());
System.out.println();
// here we are shuffling more than once
// shuffle 1
Collections.shuffle(list);
System.out.println(
"The LinkedList after shuffle 1 : "
+ list.toString());
System.out.println();
// shuffle 2
Collections.shuffle(list);
System.out.println(
"The LinkedList after shuffle 2 : "
+ list.toString());
System.out.println();
// shuffle 3
Collections.shuffle(list);
System.out.println(
"The LinkedList after shuffle 3 : "
+ list.toString());
}
}
输出
The LinkedList before shuffle : [45, GFG, 2.56, 965.321, A, true]
The LinkedList after shuffle 1 : [965.321, 2.56, true, 45, GFG, A]
The LinkedList after shuffle 2 : [2.56, A, true, 45, GFG, 965.321]
The LinkedList after shuffle 3 : [GFG, A, 965.321, 45, true, 2.56]