2
java是否有一個內置的方法來排列或隨機洗牌數字或字符的數組?就像在C++中的隨機Shuffle STL?內置置換生成器
java是否有一個內置的方法來排列或隨機洗牌數字或字符的數組?就像在C++中的隨機Shuffle STL?內置置換生成器
您可以使用Collections#shuffle
List<Integer> intList = new ArrayList<Integer>();
Collections.shuffle(intList);
如果您有數字的數組,你可以使用: -
Collections.shuffle(Arrays.asList(yourArray));
'Collections.shuffle(Arrays.asList(yourArray))' – aioobe
@RohitJain - 我做到了。感謝你的回答。 – KS88
@ KS88。別客氣 :) –