1

This code gives me only first level in hierarchy of a tree. How can I check a node to the point the node is leaf and add all those children as value for parent in a TreeMap

    for (TreeItem node : root.getChildren()) {

        mytreemap.put(node.getValue().toString(), node.getChildren());
    }

It gives

{a = [TreeItem [ value: 1, [ TreeItem [ value: 2], b= [TreeItem [ value:b1]} 

I need to have { a = [1,2] b= [b1,b2,b2-1,b2-2]}

a
  1
  2
b
  b1
 -b2
    b2-1
    b2-2
Iman
  • 769
  • 1
  • 13
  • 51
  • 1
    In general, it's a [tree traversal](http://en.wikipedia.org/wiki/Tree_traversal) - [Java implementation](http://stackoverflow.com/questions/15306452/traversing-through-all-nodes-of-a-binary-tree-in-java). – jewelsea Mar 12 '15 at 20:47

0 Answers0