0
I have this method to generate random numbers in a 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’t do this method:
public static void gerarAleatorio(List<Integer> lista) {
lista = aleatorios.stream().collect(Collectors.toList());
and receive the random list at the end, with the Collectors
.
The second code is incomplete. Try to complete it so the answer can be appropriate.
– E.Thomas
It gives some compilation error saying that
aleatorios
was not declared in its second method? Moreover, where does its second method call theMath.random()
?– Victor Stafusa