List contacts = getContacts(); // 獲取集合
for (Contact c : contacts) { // for-each 循環
writeToSystem(c); // 寫入系統
}
for (int i = 0; i < contacts.size(); i++) {
Contact c = contacts.get(i);
writeToSystem(c);
}
Iterables.withIndex (Guava)。ConcurrentModificationException。需用 Iterator.remove() 或收集待刪列表後批量處理。contacts.forEach(this::writeToSystem); 更簡潔。