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

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

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -

asp.net - call stack missing info on mono with apache and mod_mono -