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 -

xslt - Umbraco and EXSLT sets do not work -

php - How can I merge Nodes & Webform Submissions into instances of one general Content Type in Drupal 6? -