所以我在理解这段代码时遇到了一些困难。 for-each从数组中输入字符串以及计数相同字符串数的计数器,但计数器如何执行此操作?使用计数器将数组插入到散列表中
什么是获取传递在对抗数:Integer count = map.get(nextString);
什么做的if语句吗?
HashMap<String, Integer> map = new HashMap<>();
for (String nextString : inArray) {
Integer count = map.get(nextString);
if (count == null) {
count = 1;
} else {
count = count + 1;
}
map.put(nextString, count);
}
究竟是什么问题? –
你知道Java HashMap是如何工作的吗? –