Random data out of a list.
Say for example i create an array in the form,
how can I get an element of the list randomly for use, and then remove it from the list.
ArrayList<Integer> list = new ArrayList<Integer>();
//Data inside the list are the numbers from 0-9
for(int i = 0; i < 10; i++)
Re: Random data out of a list.
Just get a random number and remove the element at that index, as follows:
int rand = new Random().nextInt(list.size());
Another alternative would be to use Collections.shuffle(List<?> list) to shuffle your ArrayList and pick the first few from the ArrayList.