Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HashMap<A, B> myMap = new HashMap<A, B>();
- ...
- myMap.put(...)
- ...
- Set<A> keys = myMap.keySet();
- HashMap<A, B> myMap = new HashMap<A, B>();
- ...
- myMap.put(key, value);
- ...
- for (Entry<A, B> e : myMap.entrySet()) {
- A key = e.getKey();
- B value = e.getValue();
- }
- //// or using an iterator:
- // retrieve a set of the entries
- Set<Entry<A, B>> entries = myMap.entrySet();
- // parse the set
- Iterator<Entry<A, B>> it = entries.iterator();
- while(it.hasNext()) {
- Entry<A, B> e = it.next();
- A key = e.getKey();
- B value = e.getValue();
- }
- HashMap<A, B> myMap = new HashMap<A, B>();
- ...
- myMap.put(key, value);
- ...
- for (A key : myMap.keySet()) {
- B value = myMap.get(key); //get() is less efficient
- } //than above e.getValue()
- // for parsing using a Set.iterator see example above
- HashMap<A, B> myMap = new HashMap<A, B>();
- ...
- myMap.put(key, value);
- ...
- for (B value : myMap.values()) {
- ...
- }
- //// or using an iterator:
- // retrieve a collection of the values (type B)
- Collection<B> c = myMap.values();
- // parse the collection
- Iterator<B> it = c.iterator();
- while(it.hasNext())
- B value = it.next();
- }
- Set<A> keys = myMap.keySet();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement