Question : 2 levels treeMap

This a continuation to question

http://www.experts-exchange.com/Programming/Languages/Java/Q_26346400.html

What I need to do now,
I need to traverse a tree and store some values (if some conditions are true) in another structure
The value is structured as follow:
Node1:
Element1{ name1, value1}
Element2{name2, value2}

Node2:
Element1{ name1, value1}
Element2{name2, value2}

Node3
    SubNode3:
      Element1{ name1, value1}
Element2{name2, value2}

So the depth of the tree is no more than 2 (element under node or element under subnode under node)
What is the best structure to hold that ? some combination of map and tree would be very useful , I guess a TreeMap ?
Is there a sample code on how to do that ? going two levels down ?

Thanks

Answer : 2 levels treeMap

i guess you just need to have nested treemap only.
Also Create an element class with 2 attributes: key and value

something like

TreeMap parentTM = new TreeMap();
TreeMap childTM1 = new TreeMap();
TreeMap childTM2 = new TreeMap();
Element elem1 = new Element(key, value);
...
// Put elements to the map
childTM1.put("1", elem1 );
childTM1.put("2", elem2 );

childTM2.put("1", elem1 );
childTM2.put("2", elem2 );

parentTM.put("1", childTM1 );
parentTM.put("2", childTM2 );
Random Solutions  
 
programming4us programming4us