我目前正在尝试使用SAX编写一个XML解析器,并希望将XML文件的元素保存到Hashtable中,但为此,我需要在第一个表中使用另一个元素(如下所示):
Hashtable<String, Hashtable<String, Set>> table;我的问题是,是否有可能解决第二个哈希表,如果可能,我如何做到这一点?
发布于 2015-03-25 05:04:52
如下所示:
public static void main (String[] args) throws java.lang.Exception
{
Map<String, Map<String, Set<Integer>>> mapOfMaps = new Hashtable<String, Map<String, Set<Integer>>>();
Set<Integer> is = new HashSet<Integer>();
is.add(3);
Map<String, Set<Integer>> innerMap= new Hashtable<String, Set<Integer>>();
innerMap.put("Your Key", is);
mapOfMaps.put("Your Key Outer", innerMap);
Map<String, Set<Integer>> res = mapOfMaps.get("Your Key Outer");
Set<Integer> innerRes = innerMap.get("Your Key");
if (innerRes.contains(3)){
System.out.println("Hello world.");
}
}我建议存储第一个get的结果的原因是,您应该检查那里是否有null,或者事先执行一个包含(如果您经常使用它,这会更有效)。
https://stackoverflow.com/questions/29242665
复制相似问题