File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vivek Kr Agrawal
Ranch Hand
Posts: 51
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic