i going through how java classes , interfaces designed , saw java/util/map.java
, got below doubt ? please me answering.
what reason behind interface map
have inner interface entry
?
please see source code of java/util/map.java , answer.
map<k,v>
can viewed associative storage (i.e. container connects keys values). can viewed collection of pairs, first element key, , second element corresponding value.
the majority of methods in map<k,v>
supports associative container view of map. map.entry<k,v>
interface there support other view of map - i.e. collection of key-value pairs.
each map provides access called entry set, set of pairs map. each pair represented instance of map.entry<k,v>
.
map<integer,string> mymap = ... (map.entry<integer,string> e : mymap.entryset()) { system.out.println(e.getkey()+" ---> "+e.getvalue()); }
one have defined mapentry<k,v>
interface outside map<k,v>
. however, since interface closely related map, decision nest interface inside map makes perfect sense.
Comments
Post a Comment