• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection 3  RSS feed

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please expain the following


Iterator i = mymap.entrySet().iterator();

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Aruna Balasuriya wrote:Please expain the following



Well, what do you think?
 
author & internet detective
Marshal
Posts: 37896
594
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aruna,
Can you elaborate on what part you don't understand:

1) Iterator
2) mymap.entrySet()
3) .iterator()
 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant understand

2)mymap.entrySet()


how this part enable to call iterator() method as Map interface do not contain iterator() method.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

API description of Map's method entrySet:
Set<Map.Entry<K,V>> entrySet()

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:
a set view of the mappings contained in this map


So, in your case:
1. Map mymap = new ...;
2. Set myset = mymap.entrySet() ;
3. Iterator it = myset.iterator();


Regards,
Rok

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!