I am using this to try to display all the characters in the array but all it prints is “g”
I tested the same code using System.out.println() in regular java and it works fine
String testarray[]={"a","s","d","f","g"};
for(int l=0; l<testarray.length; l++){
String temp="";
temp=temp+testarray[l];
display.setText(""+temp);
}
Thanks!
By your code, I will avoid what others are saying and I’ll explain to you in simple laymen terms:
In plain english, there is a difference between set and print.
When you set something, you replace whatever was there with a new value. When you print, you append something to whatever was there.
System.out.printthus appends stuff, whilesetTextsets stuff instead.The
forhappens so fast (computer can compute gazillion stuffs faster than you can blink) that you see a bunch ofsetTextstuff in succession, and end up with only “g”. That’s why you need, as others said, to “append” stuff.However, simpler than what others have said, there is only one line that you need inside this whole for loop.
And that is all you need.