+ 1

Any way to randomly shuffle elements in an array in Java?

I want to create a variable (example[1,2,3,4,5,6...]) and be able to randomly arrange the elements within the variable (example[5,1,3,2,6,4...]) with as many elements I want. Pretty new to java so a simple answer or a well-explained answer would be preferable :)

4th Apr 2017, 6:34 AM
Kasey Paccagnan
Kasey Paccagnan - avatar
1 Answer
+ 7
There are many ways to do this, but the simplest way is this : Java have shuffle function inside Collection. So you can temporary convert your array into a collection, and then shuffle it.
4th Apr 2017, 6:57 AM
Wen Qin
Wen Qin - avatar