November 2006
Intermediate to advanced
224 pages
3h 29m
English
// For a set or list // collection is the set or list object for (Iterator it=collection.iterator(); it.hasNext(); ) { Object element = it.next(); } // For keys of a map for (Iterator it =map.keySet().iterator(); it.hasNext(); ) { Object key = it.next(); } // For values of a map for (Iterator it =map.values().iterator(); it.hasNext(); ) { Object value = it.next(); } // For both the keys and values of a map for (Iterator it =map.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry)it.next(); Object key = entry.getKey(); Object value = entry.getValue(); } |
The java.util package contains an Iterator class that makes iterating over a collection a relatively simple task. To iterate over a collection object, ...
Read now
Unlock full access