This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I would like to represent a (or many) Tree that may have more than one top node and children beneath them. All content is of String datatype and the end application is a Swing application where users should be shown the hierarchy of a selected top node in a tree structure.
so if user clicks a Root 2... then i should be able to show him Root2's hierarchy... i.e. Root 2 has Child 3 & Child 4... & Child 3 has GrandChild31... so on
Currently I have thought to use the all the Roots as a separate list and a single hashmap for parent child mapping. So if a particular root is asked i will traverse the hashmap and print all its children. Is the Collection structure I use good?
<edit>Sorry that the alignment of Root and Child in the quote is not spaced up properly like i gave. Root2 has Child3 and Child4 in it..</edit>
"If the facts don't fit the theory, get new facts" --Albert Einstein
Joined: May 31, 2011
Thanks Stephen & Hunter - I expect each of the top nodes to have at the least of 1000 children. So was worried if implementing each node as a custom class object might hit the performance. Another option I got from searching other forums is just use a JTree given by Swing. But I dont know how a Swing view implementation like JTree would suffice the requirement. I will try that too.