import java.util.*; public class ETest{ public static void main(String[] args){ //方法一 Map m = new HashMap (); Set > s = m.entrySet(); Iterator > it = s.iterator(); while(it.hasNext()){ Map.Entry e = it.next(); String ey = e.getKey(); int value = e.getValue(); System.out.println(ey + " " + value); } //方法二 for (Map.Entry entry:m.entrySet()) { System.out.println("Key:"+entry.getKey()); System.out.println("Value:"+entry.getValue()); } } }
遍历Map的两种方法
最新推荐文章于 2022-10-21 19:37:21 发布