Java:如何随机遍历数组?

dee*_*dee 0 java random

我有一个x大小的数组,我需要随机浏览一下这个列表,但是每个元素一次.最有效的方法是什么?

gho*_*555 8

你要找的是洗牌

试试这个-

// Create a list
List list = new ArrayList();

// Add elements to list

// Shuffle the elements in the list
Collections.shuffle(list);

// Create an array
String[] array = new String[]{"a", "b", "c"};

// Shuffle the elements in the array
Collections.shuffle(Arrays.asList(array));
Run Code Online (Sandbox Code Playgroud)