-2

我知道我可以做一个循环,但是我如何让它同时遍历其中的两个???另外,我不知道列表的大小,所以我不能使用 for 循环。相反,可能需要使用一个while循环......它会是一个大布尔表达式吗?

我会尽我所能,感谢一些想法。

4

1 回答 1

1

这是用两个迭代器完成的:

for (Iterator<String> it1 = list1.iterator(), it2 = list2.iterator(); 
     it1.hasNext() && it2.hasNext();) 
{
   final String s1 = it1.next(), s2 = it2.next();
   // stuff to do
}
于 2012-11-08T19:36:06.667 回答