如何显示字符串数组并为每个字符串换行
How can I make a string array display and make a new line for each string
String [] arrData = new String []{"League Of Lengends#PC","Crisis 3#PC","GTA#Xbox","Dying light#PC",
"Destiny#PS3","Skate#Xbox","Dying light#Xbox","Bloodborne#PS3","Crisis 3#Xbox",
"GTA#PS3","Age of Empires#PC","Crisis 3#PS3","Dying light#PS3","Skate#PC",
"Destiny#Xbox","Skate#PS3","GTA#PC","Counter Strike#PC","Counter Strike#Xbox"};
我可以让字符串显示
System.out.println(Arrays.toString(arrData));
Output:
[League Of Lengends#PC, Crisis 3#PC, GTA#Xbox, Dying light#PC,..., Counter Strike#Xbox]
现在我想把每个游戏放到一个新的行上
Output:
League Of Lengends#PC
Crisis 3#PC
GTA#Xbox
...
我已经试过了,还没有找到办法,你能帮帮我吗?
你试过遍历数组吗?
//loop through the array
for(int i = 0; i < arrData.length; i++){//begin for loop
//print each index on a new line
System.out.println(arrData[i]);
}//end for loop
您可以使用 foreach
循环:
for(String game : arrData ){
System.out.println(game);
}
String [] arrData = new String []{"League Of Lengends#PC","Crisis 3#PC","GTA#Xbox","Dying light#PC",
"Destiny#PS3","Skate#Xbox","Dying light#Xbox","Bloodborne#PS3","Crisis 3#Xbox",
"GTA#PS3","Age of Empires#PC","Crisis 3#PS3","Dying light#PS3","Skate#PC",
"Destiny#Xbox","Skate#PS3","GTA#PC","Counter Strike#PC","Counter Strike#Xbox"};
我可以让字符串显示
System.out.println(Arrays.toString(arrData));
Output:
[League Of Lengends#PC, Crisis 3#PC, GTA#Xbox, Dying light#PC,..., Counter Strike#Xbox]
现在我想把每个游戏放到一个新的行上
Output:
League Of Lengends#PC
Crisis 3#PC
GTA#Xbox
...
我已经试过了,还没有找到办法,你能帮帮我吗?
你试过遍历数组吗?
//loop through the array
for(int i = 0; i < arrData.length; i++){//begin for loop
//print each index on a new line
System.out.println(arrData[i]);
}//end for loop
您可以使用 foreach
循环:
for(String game : arrData ){
System.out.println(game);
}