Java 中遍历 Map 的几种方法
Map <string, string> map = new hashmap <string, string> (); map.put ("имя пользователя", "qq"); map.put ("пароль", "123"); map.put ("userid", "1"); map.put ("email", "[email protected]"); Map <string, string> map = new hashmap <string, string> (); map.put ("имя пользователя", "qq"); map.put ("пароль", "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 (); Итератор i = set.iterator (); while (i.hasnext ()) {map.entry <string, string> intrint1 = (map.entry <string, string>) i.next (); System.out.println (entry1.getKey ()+"=="+intrint1.getValue ()); } Set set = map.EntrySet (); Итератор i = set.iterator (); while (i.hasnext ()) {map.entry <string, string> intrint1 = (map.entry <string, string>) i.next (); System.out.println (entry1.getKey ()+"=="+intrint1.getValue ()); }用 Keyset () 迭代
Итератор 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); }用 intrySet () 迭代
Итератор IT = map.EntrySet (). Iterator (); System.out.println (map.EntrySet (). Size ()); String Key; Строковое значение; while (it.hasnext ()) {map.entry entry = (map.entry) it.next (); key = entry.getKey (). ToString (); value = entry.getValue (). ToString (); System.out.println (key+"===="+value); }以上就是对 Java 遍历 Map 的资料整理 , 后续继续补充相关资料 , 谢谢大家对本站的支持!