Iterator
- Universal Cursor (ใช้กับทุก Collection)
- มีเมธอด
remove()→ ลบขณะ iterate ได้ - Not Legacy (ใหม่กว่า)
- ใช้กับ: HashMap, LinkedList, ArrayList, HashSet, TreeMap, TreeSet, ฯลฯ
- แก้ไข Collection ขณะ iterate ได้ (ผ่าน remove)
Enumeration
- Not Universal (ใช้กับ Legacy classes เท่านั้น)
- ไม่มีเมธอด
remove() - Legacy Interface (เก่า)
- Read-only: ไม่สามารถแก้ไขขณะ iterate
- ใช้กับ: Vector, Hashtable
สรุป
| คุณสมบัติ | Iterator | Enumeration |
|---|---|---|
| Universality | ทุก Collection | Legacy เท่านั้น |
| Remove method | มี | ไม่มี |
| Legacy | ไม่ | ใช่ |
| Modification | ได้ (ผ่าน remove) | ไม่ได้ (Read-only) |
| Collections | ทุกตัว | Vector, Hashtable |