是否可以像下面这样在 for 循环中包含字符串“arrayNames”:for (String s:arrayLocations +String otherOne:arrayNames)
?我知道这段代码是错误的,但这只是为了让大家理解。
String[] arrayLocations = formattedLocations.split(",");
String[] arrayNames = formattedNames.split(",");
for(String s:arrayLocations)
{
Toast.makeText(context, s, Toast.LENGTH_LONG).show();
Toast.makeText(context, toBeAdded, Toast.LENGTH_LONG).show();
}
最佳答案
假设数组长度相同,
String[] arrayLocations = formattedLocations.split(",");
String[] arrayNames = formattedNames.split(",");
for(int i = 0; i < arrayLocations.length; i++ )
{
Toast.makeText(context, arrayLocations[i], Toast.LENGTH_LONG).show();
Toast.makeText(context, arrayNames[i], Toast.LENGTH_LONG).show();
}
关于java - 是否可以在 Java 中对两个字符串数组使用一个 for 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36179980/