Java 中遍历 peta 的几种方法
Peta <string, string> peta = new HashMap <String, String> (); peta.put ("nama pengguna", "qq"); peta.put ("kata sandi", "123"); peta.put ("userid", "1"); peta.put ("email", "[email protected]"); Peta <string, string> peta = new HashMap <String, String> (); peta.put ("nama pengguna", "qq"); peta.put ("kata sandi", "123"); peta.put ("userid", "1"); peta.put ("email", "[email protected]");第一种用 untuk 循环
untuk (map.entry <string, string> entri: map.entryset ()) {system.out.println (entry.getKey ()+"--->"+entry.getValue ()); } untuk (map.entry <string, string> entri: map.entryset ()) {System.out.println (entry.getKey ()+"--->"+entry.getValue ()); }第二种用迭代
Set set = map.entryset (); Iterator i = set.iterator (); while (i.hasnext ()) {map.entry <string, string> entri1 = (map.entry <string, string>) i.next (); System.out.println (entri1.getKey ()+"=="+entri.getValue ()); } Set set = map.entryset (); Iterator i = set.iterator (); while (i.hasnext ()) {map.entry <string, string> entri1 = (map.entry <string, string>) i.next (); System.out.println (entri1.getKey ()+"=="+entri.getValue ()); }用 keyset () 迭代
Iterator it = map.keyset (). Iterator (); while (it.hasnext ()) {string key; Nilai string; key = it.next (). ToString (); value = map.get (key); System.out.println (key+"-"+nilai); } Iterator it = map.keyset (). Iterator (); while (it.hasnext ()) {string key; Nilai string; key = it.next (). ToString (); value = map.get (key); System.out.println (key+"-"+nilai); }用 Entryset () 迭代
Iterator it = map.entryset (). Iterator (); System.out.println (map.entryset (). Size ()); Tombol string; Nilai string; while (it.hasnext ()) {map.entry entri = (map.entry) it.next (); key = entry.getKey (). ToString (); value = entry.getValue (). ToString (); System.out.println (key+"===="+nilai); }以上就是对 Java 遍历 peta 的资料整理 , 后续继续补充相关资料 , 谢谢大家对本站的支持!