0
listaA = new ArrayList <>();
boolean n = true;
while (listaA.size() < listab.size()) {
Log.i( "while ordena" , String.valueOf( listaA.size() ));
valorAl = nRandom.nextInt( listab.size() );
Log.i( "while ordena" , " valor random " + String.valueOf( valorAl ));
if (valorAl == listab.size()) {
valorAl = valorAl - 1;
Log.i( "while ordena" , " valor random igual a listab.size");
}
if (n) {
listaA.add( listab.get( valorAl ) );
Log.i( "while ordena" ," 1 valor na lista A");
n = false;
} else {
Log.i( "while ordena" , " proximo valor da lista A - " + String.valueOf( listab.get( valorAl ).id ) );
Boolean igual =false;
//int y =0;
for (int y =0; y==(listaA.size()-1); y++){
if (listaA.get(y).id== listab.get( valorAl ).id ) {igual=true; Log.i( "while ordena" , " já existe");}
if(!igual) {listaA.add( listab.get( valorAl ) );
Log.i( "while ordena" , " adiciona novo");}
}
}
}
I am using this code to sort randomly the listA with the elements of the listb. The thing is, it only goes through the for when the 2 element A is added to the listA and then it doesn’t go back into the for. I’m more used to using Vb and there the code works normally, but in android studio is in an infinite loop, because no element is added to the listA. I don’t know if I’ve missed something so that it can be executed correctly, since I’m not very used to the java language.
Edit: I put the int y=0 out of the for to see if it was the y that held the value after the first run of the for, but it has the same effect, it only goes into the for 1 time. So I don’t understand why the is not being executed again.
How many values does the
listab
?– igventurelli