Randomly iterate over ArrayList<Integer> in Java -


seems basic question. i've arraylist<integer> al , iterate on it. normally,

for(int : al) {     // code } 

does trick. requirement iterate not in sequence randomly.

you can use collections.shuffle() on list.

note shuffle list itself, if order important should make copy of (and shuffle copy).

alternatively create random array has elements 0 - list.size()-1 , using indices access "random" elements in list.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -