Seems a very basic question. I\'ve an ArrayList
and I would like to iterate over it. Normally,
for(int i : al) {
// some c
You can use Collections.shuffle() on the list.
Note that this will shuffle the list itself, so if order is important you should make a copy of it (and shuffle the copy).
List newList = new ArrayList<>( oldList ) ;
Collections.shuffle( newList ) ;
Alternatively you could create a random array which has elements 0 - List.size()-1
and using those as indices to access "random" elements in the List
.