File tree Expand file tree Collapse file tree
src/main/java/cn/byhieg/collectiontutorial/maptutorial Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package cn .byhieg .collectiontutorial .maptutorial ;
22
3+ import java .util .HashMap ;
4+ import java .util .Iterator ;
5+ import java .util .Map ;
6+
37/**
48 * Created by shiqifeng on 2017/2/24.
59 * Mail byhieg@gmail.com
610 */
711public class HashMapExample {
812
9-
10- public static void main (String [] args ) {
13+ public Map <String , String > insertMap (){
14+ HashMap <String , String > maps = new HashMap <>(10 );
15+ for (int i = 0 ; i < 10 ;i ++) {
16+ maps .put (i + "" , i + "" );
17+ }
18+ return maps ;
19+ }
1120
1221
22+ public void getValue (Map <? extends String ,? extends String > maps ,String key ) {
23+ System .out .println (maps .get (key ));
1324 }
1425
1526
27+ public void getAllKeyAndValue (Map <? extends String , ? extends String > maps ) {
28+ Iterator iterator = maps .entrySet ().iterator ();
29+ while (iterator .hasNext ()) {
30+ Map .Entry <String , String > entry = (Map .Entry <String , String >) iterator .next ();
31+ System .out .println (entry .getKey ());
32+ System .out .println (entry .getValue ());
33+ }
34+ }
35+
1636}
You can’t perform that action at this time.
0 commit comments