Java 中遍历 Carte 的几种方法
Map <string, string> map = new hashmap <string, string> (); map.put ("nom d'utilisateur", "qq"); map.put ("mot de passe", "123"); map.put ("utilisateur", "1"); map.put ("email", "[email protected]"); Map <string, string> map = new hashmap <string, string> (); map.put ("nom d'utilisateur", "qq"); map.put ("mot de passe", "123"); map.put ("utilisateur", "1"); map.put ("email", "[email protected]");第一种用 pour 循环
pour (map.entry <string, string> entrée: map.entryset ()) {System.out.println (entry.getKey () + "--->" + entry.getValue ()); } pour (map.entry <string, string> entrée: 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 (entrée1.getKey () + "==" + entrée1.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 (entrée1.getKey () + "==" + entrée1.getValue ()); }用 keyset () 迭代
Iterator it = map.KeySet (). Iterator (); while (it.hasnext ()) {string key; Valeur de chaîne; key = it.next (). toString (); valeur = map.get (key); System.out.println (clé + "-" + valeur); } Iterator it = map.KeySet (). Iterator (); while (it.hasnext ()) {string key; Valeur de chaîne; key = it.next (). toString (); valeur = map.get (key); System.out.println (clé + "-" + valeur); }用 entrée () 迭代
Iterator it = map.entryset (). Iterator (); System.out.println (map.EntrySet (). Size ()); Clé de chaîne; Valeur de chaîne; while (it.hasnext ()) {map.entry entrée = (map.entry) it.next (); key = entry.getKey (). toString (); Value = entry.getValue (). ToString (); System.out.println (clé + "====" + valeur); }以上就是对 Java 遍历 Carte 的资料整理 , 后续继续补充相关资料 , 谢谢大家对本站的支持!