ArrayList<String> date=new ArrayList<String>();
ArrayList<String> time=new ArrayList<String>();
//addition of elements in the list
...
...
for(String x :date,String y: time)
{
System.out.println(x+" "+y);
}
是否可以通过单个“for each”循环迭代两个对象? 我试过上面的代码,我得到了编译错误。有语法错误吗?
最佳答案
不,这行不通。使用 for-each 循环无法做到这一点;您将不得不使用显式索引或迭代器执行正常的 for 循环。
关于java - "For each"两个对象的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30176705/