Map<String, List<String>> words = new HashMap<String, List<String>>();
List<Map> listOfHash = new ArrayList<Map>();
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String word = getTagValue("word", eElement);
List<String> add_word = new ArrayList<String>();
String pos = getTagValue("POS", eElement);
if(words.get(pos)!=null){
add_word.addAll(words.get(pos));
add_word.add(word);
}
else{
add_word.add(word);
}
words.put(pos, add_word);
}
}
这是我写的一段代码(它使用Stanford CoreNLP)。我面临的问题是,目前这个代码只与一个地图即“单词”一起工作。现在,我希望只要解析器看到“000000000”是我的分隔符,就应该将新的Map添加到List中,然后将键和值插入到它中。如果没有看到“000000000”,则键和值将被添加到相同的地图中。 请帮助我,因为即使经过很多努力,我也无法做到这一点。HashMap的列表Java
您能否举个例子? –