Skip to content Skip to sidebar Skip to footer

Android For Loop

I have the following code... String t = ' '; for(int l=0; l<=5; l++){ t = 'Num: ' + l + '\n'; } VarPrueba.setText(t); I am wanting to loop through a set of numbers, and g

Solution 1:

Change as follow:

t+="Num: " + l + "\n";

And the most effective way to do this is to using StringBuilder, Something like:

StringBuilder t = new StringBuilder(); 
for(int l=0; l<=5; l++){
    t.append("Num:");
    t.append(l+"\n");
}

VarPrueba.setText(t.toString());

Post a Comment for "Android For Loop"