Finding the key of HashMap which holds the lowest integer value(找到保存最小整数值的 HashMap 的键)
问题描述
我正在为需要学习最常用单词的年轻学生创建一个教育游戏.我随机选择列表中的三个单词,将它们显示在屏幕上,播放三个单词之一的录音,然后学生必须选择已经发音的单词.我记录了他们每个单词猜了多少次.通过这种方式,我可以为何时应该向学生介绍新单词设置一个标准.When three of the words are picked I'll like to pronounce the word that the student has had least exposure to.
I'm creating an educational game for young students who needs to learn the most common words. On random I pick three words of the list, show them on the screen, play an audio recording of one of the three words and then the student has to pick the word that has been pronounced. I keep track of how many times they have guessed each word. In that way I can set up a criteria for when new words should be introduced to the student. When three of the words are picked I'll like to pronounce the word that the student has had least exposure to.
我有一个名为 words 的 HashMap,其中包含单词,以及学生猜出单词的次数的整数值.
I have a HashMap called words, which contains the words, and a integer value of how many times the student guessed the word.
HashMap<String,Integer> words
它包含 10 - 120 个键/词.我想创建一个方法,它将三个哈希映射键作为参数,它可以返回具有最低要求键值的字符串/键.
It contains between 10 - 120 keys/words. I'll like to create a method, which takes three of the hash map keys as parameters, that can return the String/key having the lowest value of the keys asked for.
我很难让它按预期工作,如果能提供任何帮助,我将不胜感激.
I have had trouple getting this to work as intended and I'd appreciate any help.
推荐答案
这个怎么样?
private String getMinKey(Map<String, Integer> map, String... keys) {
String minKey = null;
int minValue = Integer.MAX_VALUE;
for(String key : keys) {
int value = map.get(key);
if(value < minValue) {
minValue = value;
minKey = key;
}
}
return minKey;
}
这篇关于找到保存最小整数值的 HashMap 的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:找到保存最小整数值的 HashMap 的键
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01