3-Java_CollectionFramework_Examples_New_10c
3-Java_CollectionFramework_Examples_New_10c
Framework: Examples
Using Set
5
Map views
• Set<Map.Entry<K, V>> entrySet()
Returns a set view of the mappings contained in
this map.
• A view is dynamic access into the Map
If you change the Map, the view changes
If you change the view, the Map changes
• The Map interface does not provide any Iterators
However, there are iterators for the above Sets
and Collections
6
import java.util.HashMap;
import java.util.Set;
//Creating a Set
Set set = map.entrySet();
if(v.contains(new Integer(3)))
System.out.println("Vector contains 3.");}
Using ListIterator
. you can also obtain an iterator by
For collections that implement List,
calling ListIterator which can traverse the list in either direction
ArrayList al = new ArrayList();