- Map<String, String> map = new HashMap<String, String>();
- map.put("1", "11");
- map.put("2", "22");
- System.out.println("里面的值有:");
- Collection<String> connection = map.values();
- Iterator<String> iterator = connection.iterator();
- while (iterator.hasNext()) {
- System.out.println(iterator.next() + "..");
- }
- System.out.println("里面的键有:");
- Set<String> key = map.keySet();
- for (String string : key) {
- System.out.println(string);
- }
- System.out.println("里面的键值对是:");
- Set<Map.Entry<String, String>> set = map.entrySet();
- Iterator<Map.Entry<String, String>> iterator2 = set.iterator();
- while (iterator2.hasNext()) {
- Map.Entry<String, String> entry = iterator2.next();
- System.out.println("键是:" + entry.getKey() + "值是:" + entry.getValue());
- }
java 之HashMap取值
最新推荐文章于 2022-07-15 18:14:15 发布