NodeList nList2 = doc.getElementsByTagName("dep");
Map<String, List<Map<String, String>>> depMap = new HashMap<String, List<Map<String, String>>>();
for (int temp = 0; temp < nList2.getLength(); temp++) {
Element el = (Element)nList2.item(temp);
String type=el.getAttribute("type");
Node nNode = nList2.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
List<Map<String,String>> depList = new ArrayList<Map<String,String>>();
String governor = getTagValue("governor", eElement);
String dependent = getTagValue("dependent", eElement);
Map<String, String> govdepmap = new HashMap<String, String>();
govdepmap.put(governor, dependent);
depList.add(govdepmap);
List<Map<String,String>> flist = new ArrayList<Map<String,String>>();
flist.add(govdepmap);
depMap.put(type, flist);
}
}
我写了这段代码,但问题是每当循环运行时,它都会替换已经存储在 depMap 中的 List。我希望它应该在从 depMap 检索到的 List 中附加新 Map 而不是替换它。