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 randomly sort the ListA with list elements. It turns out that it only goes through when the element 2 is added to the listA and then it does not re-enter the for. I'm more accustomed to using vb and there the code works normally, but in android studio it gets in an infinite loop because no element is added to the listA anymore. I do not know if something was missing, so that it is executed correctly, since it is not very used to Java language.
edit: I put the int y = 0 out of for to see if it would be the y that held the value after the first execution of the, but has the same effect, only goes in for 1 time. That's why I'm not realizing why it is not running again.