This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to store a tree(node with parent child relationship) in java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to store a tree(node with parent child relationship) in java" Watch "How to store a tree(node with parent child relationship) in java" New topic
Author

How to store a tree(node with parent child relationship) in java

Vivek Kr Agrawal
Ranch Hand

Joined: Sep 08, 2012
Posts: 32

Hi all,
I am getting a tree with some child nodes from db. I want to store them in a proper variable like Hashmap or linkedhashmap or sortedset. But it should be able to go up to n-level in hierarchy. I am confused how to achieve that.


Please suggest some efficient ways or some similar examples.

Thanks in advance,
Vivek
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Why not use a structure that's fit for a tree representation - like an actual tree structure. You can use DefaultMutableTreeNode if you don't feel like program any yourself. Although it's part of Swing, it can be used independently.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to store a tree(node with parent child relationship) in java
 
Similar Threads
Store Data in Tree Node
Adding CheckBox and Text as child of a tree
Which technology to use to render tree structure on UI.
Create JTree using data from Map
How to save parent child objects in mongodb