Java中遍历マップ的几种方法
map <string、string> map = new hashmap <string、string>(); map.put( "username"、 "qq"); map.put( "password"、 "123"); map.put( "userid"、 "1"); map.put( "email"、 "[email protected]"); map <string、string> map = new hashmap <string、string>(); map.put( "username"、 "qq"); map.put( "password"、 "123"); map.put( "userid"、 "1"); map.put( "email"、 "[email protected]");
第一种用のため
for(map.entry <string、string> entry:map.entryset()){system.out.println(entry.getKey()+"--->"+entry.getValue()); } for(map.entry <string、string> entry:map.entryset()){system.out.println(entry.getKey()+"--->"+entry.getValue()); }第二种用迭代
set set = map.entryset(); iterator i = set.iterator(); while(i.hasnext()){map.entry <string、string> entry1 =(map.entry <string、string>)i.next(); System.out.println(entry1.getKey()+"=="+entry1.getValue()); } set set = map.entryset(); iterator i = set.iterator(); while(i.hasnext()){map.entry <string、string> entry1 =(map.entry <string、string>)i.next(); System.out.println(entry1.getKey()+"=="+entry1.getValue()); }用keyset()迭代
iterator it = map.keyset()。iterator(); while(it.hasnext()){string key;文字列値; key = it.next()。toString(); value = map.get(key); System.out.println(key+" - "+value); } iterator it = map.keyset()。iterator(); while(it.hasnext()){string key;文字列値; key = it.next()。toString(); value = map.get(key); System.out.println(key+" - "+value); }用エントリセット()迭代
iterator it = map.entryset()。iterator(); system.out.println(map.entryset()。size());文字列キー;文字列値; while(it.hasnext()){map.entry entry =(map.entry)it.next(); key = entry.getKey()。toString(); value = entry.getValue()。toString(); System.out.println(key+"===="+value); }以上就是对java遍历マップ的资料整理、后续继续补充相关资料、