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

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -