要获取HashMap的值,可以使用以下方法:
使用get()方法:通过指定键来获取对应的值。例如:HashMap.get(key),其中key为要获取值的键。
遍历HashMap:使用entrySet()方法获取HashMap的键值对集合,然后遍历集合获取每个键值对的值。例如:
HashMap<String, Integer> hashMap = new HashMap<>();// 添加键值对hashMap.put("A", 1);hashMap.put("B", 2);hashMap.put("C", 3);// 遍历获取值for (Map.Entry<String, Integer> entry : hashMap.entrySet()) { Integer value = entry.getValue(); System.out.println(value);}使用values()方法:获取HashMap的值集合。例如:hashMap.values()。以上是获取HashMap值的几种常用方法,可以根据具体需求选择使用。

