gosulove gosulove - 4 months ago 13
Java Question

Android Studio VS Java -> Get Array data

I am new to Android studio. Just want to check how to get the results just like normal Netbeans when i run this coding

In Java netbeans

String[] words = {"tiger","lion","leopard"};
List<String> wordList = Arrays.asList(words);
for (String e : wordList)
{
System.out.print(e+" 123 ");

}


I get results like this : tiger 123 lion 123 leopard 123

Then for results In Android Studio if I run this

String[] words = {"tiger","lion","leopard"};
List<String> wordList = Arrays.asList(words);
String str1 = Arrays.toString(words);
for (String e : wordList)
{
get_data.setText(str1+" 123 ");
}


I get this : [tiger,lion,leopard]123

My question is how to list out the Array data just like normal Java (tiger 123 lion 123 leopard 123?

Answer

Use get_data.setText(get_data.getText().toString()+e+" 123 "); instant of get_data.setText(str1+" 123 ") .Because when you use setText(String) , it overwrite the previous data and set the new data you are gonna pass.