遍历map的几种方式
2017-05-23 15:06
337 查看
userList.put("1",new User("1","zhangsan","ddd")); userList.put("2",new User("2","lisi","ddd")); userList.put("3",new User("3","wanwu","ddd")); //1. userList.value() for(User user : userList.value()){ if(userName.equals(user.getUserName()) $$ password.equals(userPass)){ System.out.println("登录成功"); break; } } //2.userList.KeySet() 得到key的集合 for(String key : userList.keySet()){ System.out.println("key-->" + key + "value-->" + userList.get(key).getUserName()); } //3.Iterator Map转为set Iterator<Map.Entry<String,User>> it = userList.entrySet().iterator(); while(it.hasNext()){ Map.Entry<String,User> entry = it.next(); System.out.println("key-->" + entry.getKey + "value-->" + entry.getValue().getUserName()); } //4.userList.entrySet() Map转为set for(Map.Entry<String,User> entry : userList.entrySet()){ System.out.println("key-->" + entry.getKey + "value-->" + entry.getValue().getUserName()) }
相关文章推荐
- map集合的遍历的几种方式
- Java遍历Map数据的几种方式
- List和Map常用的几种遍历方式
- Java中遍历Map的几种方式
- Java之List和Map的几种遍历方式
- map遍历的几种方式
- 【Java】Map集合的几种遍历方式
- java中遍历map的几种方式
- Java种遍历Map集合的几种常用方式
- Map遍历几种方式
- 遍历map的几种方式
- HashMap简单实现原理及遍历map的几种方式
- think in java读后总结---Map集合的几种遍历方式
- Map集合的几种遍历方式
- JAVA遍历map的几种方式
- 遍历map的几种方式
- java遍历Map的几种方式
- List及Map遍历的几种方式
- Map的几种迭代器遍历方式
- map集合的几种遍历方式