// modifying values in-place through iteration: for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) { it.advance(); if ( satisfiesCondition( it.key() ) { it.setValue( newValueForKey( it.key() ) ); } }
// deleting entries during iteration: for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) { it.advance(); if ( satisfiesCondition( it.key() ) { it.remove(); } }
// faster iteration by avoiding hasNext(): TIntIntIterator iterator = map.iterator(); for ( int i = map.size(); i-- > 0; ) { iterator.advance(); doSomethingWithKeyAndValue( iterator.key(), iterator.value() ); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|