Inbuilt Permutation Generator

余生长醉 提交于 2019-12-02 05:04:30

问题


Does java have an inbuilt method to permute or randomly shuffle an Array of numbers or characters? Something like Random Shuffle STL in c++??


回答1:


You can use Collections#shuffle

List<Integer> intList = new ArrayList<Integer>();
Collections.shuffle(intList);

If you have an array of numbers, you can use: -

Collections.shuffle(Arrays.asList(yourArray));


来源:https://stackoverflow.com/questions/12943118/inbuilt-permutation-generator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!