Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何找到存储在链表中的值,而不是存储在hashmap中的值_Java_Linked List_Hashmap - Fatal编程技术网

Java 如何找到存储在链表中的值,而不是存储在hashmap中的值

Java 如何找到存储在链表中的值,而不是存储在hashmap中的值,java,linked-list,hashmap,Java,Linked List,Hashmap,我有下面的hashmap,它存储字符串键和链表值 public HashMap<String, LinkedList<String>> wordIndex = new HashMap<>(); 但是,它总是返回none,这意味着它可以在链接列表中找到单词。 那么,在Hashmaps中遍历链表的正确过程是什么呢。我搜索了一下,但找不到任何答案 我还需要返回包含查询词的所有键(在本例中为“算法”)。我似乎在hashmap类中找不到一个函数可以做到这一点(或者可能

我有下面的hashmap,它存储字符串键和链表值

public HashMap<String, LinkedList<String>> wordIndex = new HashMap<>();
但是,它总是返回none,这意味着它可以在链接列表中找到单词。 那么,在Hashmaps中遍历链表的正确过程是什么呢。我搜索了一下,但找不到任何答案


我还需要返回包含查询词的所有键(在本例中为“算法”)。我似乎在hashmap类中找不到一个函数可以做到这一点(或者可能我看到了但不理解它)。我是hashmaps新手,你们能帮我一个忙,给我指出正确的方向吗。

你们不能这么做。如果要检查HashMap中的任何LinkedList中是否有该单词,应执行以下操作:

String getWord(String query) { //query=user input in this case algorithms
    for(LinkedList<String> l : wordIndex.values()) {
        if(l.contains(query.toLowerCase())) {
            return "hello";          //should return hello if word is found
        }
    }
    return "none";   
}
stringgetword(stringquery){//query=本例中的用户输入
for(LinkedList l:wordIndex.values()){
if(l.contains(query.toLowerCase())){
返回“hello”;//如果找到单词,则应返回hello
}
}
返回“无”;
}

你不能那样做。如果要检查HashMap中的任何LinkedList中是否有该单词,应执行以下操作:

String getWord(String query) { //query=user input in this case algorithms
    for(LinkedList<String> l : wordIndex.values()) {
        if(l.contains(query.toLowerCase())) {
            return "hello";          //should return hello if word is found
        }
    }
    return "none";   
}
stringgetword(stringquery){//query=本例中的用户输入
for(LinkedList l:wordIndex.values()){
if(l.contains(query.toLowerCase())){
返回“hello”;//如果找到单词,则应返回hello
}
}
返回“无”;
}

你不能那样做。如果要检查HashMap中的任何LinkedList中是否有该单词,应执行以下操作:

String getWord(String query) { //query=user input in this case algorithms
    for(LinkedList<String> l : wordIndex.values()) {
        if(l.contains(query.toLowerCase())) {
            return "hello";          //should return hello if word is found
        }
    }
    return "none";   
}
stringgetword(stringquery){//query=本例中的用户输入
for(LinkedList l:wordIndex.values()){
if(l.contains(query.toLowerCase())){
返回“hello”;//如果找到单词,则应返回hello
}
}
返回“无”;
}

你不能那样做。如果要检查HashMap中的任何LinkedList中是否有该单词,应执行以下操作:

String getWord(String query) { //query=user input in this case algorithms
    for(LinkedList<String> l : wordIndex.values()) {
        if(l.contains(query.toLowerCase())) {
            return "hello";          //should return hello if word is found
        }
    }
    return "none";   
}
stringgetword(stringquery){//query=本例中的用户输入
for(LinkedList l:wordIndex.values()){
if(l.contains(query.toLowerCase())){
返回“hello”;//如果找到单词,则应返回hello
}
}
返回“无”;
}

您正在对照永远不匹配的LinkedList对象检查字符串。您正在对照永远不匹配的LinkedList对象检查字符串。您正在对照永远不匹配的LinkedList对象检查字符串。您正在对照永远不匹配的LinkedList对象检查字符串。非常感谢,所以这个过程就是使用一个增强的for循环(或者迭代器,我想也可以)。您知道如何返回键吗?您可以在
wordIndex.entrySet()
上使用for循环。En
Entry
是存储在映射中的(键、值)对。请参阅:非常感谢,所以这个过程是使用增强的for循环(或者迭代器,我想也可以)。您知道如何返回键吗?您可以在
wordIndex.entrySet()
上使用for循环。En
Entry
是存储在映射中的(键、值)对。请参阅:非常感谢,所以这个过程是使用增强的for循环(或者迭代器,我想也可以)。您知道如何返回键吗?您可以在
wordIndex.entrySet()
上使用for循环。En
Entry
是存储在映射中的(键、值)对。请参阅:非常感谢,所以这个过程是使用增强的for循环(或者迭代器,我想也可以)。您知道如何返回键吗?您可以在
wordIndex.entrySet()
上使用for循环。En
Entry
是存储在映射中的(键、值)对。见: