I have this method to generate random numbers in ArrayList
;
public static List<Integer> gerarAleatorio() {
List<Integer> aleatorios = new ArrayList<>();
while(aleatorios.size() < 6) {
int num = (int) (1 + Math.random() * 60);
if(!aleatorios.contains(num)) {
aleatorios.add(num);
}
}
return aleatorios;
}
My question is why I can not do this method like this:
public static void gerarAleatorio(List<Integer> lista) {
lista = aleatorios.stream().collect(Collectors.toList());
and receive the random list at the end, with Collectors
.