例如,對於列表{1,2,3,4},我必須比較對(1,2),(1,3),(1,4 ),(2,3),(2,4),(3,4)。與正常的方式進行循環是:使用迭代器進行「向下」迭代的優雅方式
for(i=0 ; i<list.size() ; i++){
for(j=i+1 ; j<list.size() ; j++){
//do stuff with list[i] and list[j];
}
}
我可以做這樣的事情迭代器(見下文)?
for (int i : list){
for(int j : [list after index i]){
//do stuff with list[i] and list[j];
}
}
的[克隆Java中的迭代器?(http://stackoverflow.com/questions/7758202/clone-an-iterator-in-java) – NPE 2012-02-28 13:49:13