This Code creates 50 random-numbers between 1 and 100 and adds it in an ArrayList. Now I want to search the ArrayList for the same numbers, than remove them and get a new number. In the end, the list should only contain 50 unique numbers between 1 and 100.
The Problem is: I don't know, how to search the same ArrayList for the same number, remove it and get a new one. Can someone please help me?
import java.util.Random;
import java.util.ArrayList;
class RandomPrim {
public static void main(String[] args) {
Random nr = new Random();
int number;
ArrayList<Integer> liste = new ArrayList<Integer>();
// get 50 random numbers between 1 and 100
for(int counter = 1; counter <= 50; counter++) {
number = 1+nr.nextInt(100);
liste.add(number);
// System.out.println(liste.toString());
}
for (int ausgabe : liste) {
System.out.print(ausgabe+ ", ");
}
}
}
nextInt( availableNumbers.size() )(ofc you should remove any number you took from that list).