[英]JAVA: Map.put(K, K V), doesn't Maps only have 2 values?
So I started programming 2 months ago, this maybe obvious but I have no idea how I could even google my question.所以我在 2 个月前开始编程,这可能很明显,但我不知道我怎么能用谷歌搜索我的问题。
Map<Character,Integer> characters = new HashMap<>();
for (int i = 0; i < word.length(); i++) {
char c = word.toLowerCase().charAt(i);
if(characters.containsKey(c)) {
characters.put(c,characters.get(c) + 1);
} else {
characters.put(c,1);
}
}
In the 4th line, I put a Character, then a Character and Integer pair into the map.在第 4 行中,我将一个字符、一个字符和Integer 对放入 map。
Doesn't the.put method require exactly 2 values (Key and Value)? .put 方法不需要正好2 个值(键和值)吗?
You are stil using two arguments in this line.您仍在此行中使用两个 arguments。
characters.put(c,characters.get(c) + 1);
The second argument is the operation characters.get(c) + 1
that results in a single integer.第二个参数是操作
characters.get(c) + 1
,它产生一个integer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.