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

后端 未结 7 1531
萌比男神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:05

    Use basic loop

    for(int index=0; index < list1.size() ; index++){
      list1.get(index);
      list2.get(index);
    }
    

提交回复
热议问题