Java 中遍历 Mapa 的几种方法
Map <string, string> map = new HashMap <String, String> (); map.put ("nombre de usuario", "qq"); map.put ("contraseña", "123"); map.put ("UserId", "1"); map.put ("correo electrónico", "[email protected]"); Map <string, string> map = new HashMap <String, String> (); map.put ("nombre de usuario", "qq"); map.put ("contraseña", "123"); map.put ("UserId", "1"); map.put ("correo electrónico", "[email protected]");第一种用 para 循环
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 (); Iterador 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 (); Iterador 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 ()) {clave de cadena; Valor de cadena; key = it.next (). toString (); valor = map.get (clave); System.out.println (clave+"-"+valor); } Iterator it = map.keySet (). Iterator (); while (it.hasnext ()) {clave de cadena; Valor de cadena; key = it.next (). toString (); valor = map.get (clave); System.out.println (clave+"-"+valor); }用 EntrySet () 迭代
Iterador it = map.entryset (). Iterator (); System.out.println (map.entryset (). Size ()); Tecla de cadena; Valor de cadena; while (it.hasnext ()) {map.entry entry = (map.entry) it.next (); Key = Entry.getKey (). ToString (); valor = entry.getValue (). toString (); System.out.println (clave+"===="+valor); }以上就是对 java 遍历 mapa 的资料整理 , 后续继续补充相关资料 谢谢大家对本站的支持!