给定一个非空的 ArrayList,在迭代该列表时循环其余元素的最优雅的方法是什么?
Give an ArrayList instance 'exampleList' contains five strings: ["A", "B", "C", "D", "E"]
循环遍历时:
for(String s : exampleList){
// when s is "A", I want to loop through "B"-"E", inside this loop
// when s is "B", I want to loop through "C"-"E", inside this loop
// when s is "C", I want to loop through "D"-"E", inside this loop
}
最佳答案
最好的方法可能是使用传统的 for 循环:
for (int i=0; i<exampleList.size(); i++) {
String s = exampleList.get(i);
for (int j=i+1; j<exampleList.size(); j++) {
String other = exampleList.get(j);
}
}
关于java.util.ArrayList 循环遍历循环内的其余元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29448652/