Here you can find the source of nextItem(Collection
public static <T> T nextItem(Collection<T> items, Random random)
//package com.java2s; //License from project: LGPL import java.util.Collection; import java.util.List; import java.util.Random; public class Main { public static <T> T nextItem(Collection<T> items, Random random) { int randomIndex = random.nextInt(items.size()); int count = 0; for (T item : items) { if (count == randomIndex) return item; count++;/*w w w . ja v a 2 s . c o m*/ } return null; } public static <T> T nextItem(List<T> items, Random random) { int randomIndex = random.nextInt(items.size()); return items.get(randomIndex); } }