public static void main(String[] args) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("username", "huxiao");
map.put("password", "huxiaoPassword");
// 方法一:按条取数据
for (Map.Entry<String, Object> entry : map.entrySet()) {
// System.out.println(entry);
System.out.println(entry.getKey() + " = " + entry.getValue());
}
System.out.println("------------------------------------");
// 方法二:用key循环:此方法仅在java5以后有效,而且速度比上面的那个慢
for (String key : map.keySet()) {
System.out.println(key + " = " + map.get(key));
}
}
循环Map的两种方法
最新推荐文章于 2021-03-06 18:01:18 发布