I'm currently trying to write an XML Parser with SAX and want to save the elements of an XML file into a Hashtable, but for this I need another one in that first table ( like this ):
Hashtable<String, Hashtable<String, Set>> table;
My question is whether its possible to address the second hashtable and, if so, how do I do this?
Do it like this:
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.");
}
}
The reason I recommend to store the result of the first get is that you should check for null there or do a contains beforehand (, which is more preformant, if you use it a lot).