Java How To -Shuffle an Array
How To Shuffle an Array
Randomly change the order of elements in an array usingCollections.shuffle():
Example
import java.util.Arrays;import java.util.Collections;import java.util.List;public class Main { public static void main(String[] args) { String[] fruits = {"Apple", "Banana", "Cherry", "Mango"}; List<String> list = Arrays.asList(fruits); Collections.shuffle(list); System.out.println(list); }}
