In Java, how to traverse two lists at the same time?

后端 未结 7 1527
萌比男神i
萌比男神i 2021-01-19 04:55

E.g.

for(String str : list1) {
...
}

for(String str : list2) {
...
}

suppose we are sure that list1.size() equals list2

7条回答
  •  心在旅途
    2021-01-19 05:23

    As you say that both the list are of same size, then you can use "for" loop instead of "for-each" loop. You can use get(int index) method of list to get the value during each iteration.

提交回复
热议问题