• Post Reply Bookmark Topic Watch Topic
  • New Topic

Does java have a class that has a tree data structure?  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it does, what is the import statement required, constructor parameters ect. Thanks
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java API is your friend.

For a Binary Red/Black Tree structure for storing data, see TreeMap. Or if you want a visual representation of a Tree you might look at JTree and the How to use Trees tutorial page.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your other thread you had asked about using the MutableTreeNode. This is my response:

The MutableTreeNode is a node on a tree. you should read the tutorial I mentioned in the other post. It has a section about using TreeModels, and the DefaultTreeModel. Even if you aren't using the JTree for display purposes it may be a good structure to look over for representing non-binary tree structures.

It really is just a bunch of links between nodes (parent and lists of children) with identifiers for leaf nodes.
 
Marshal
Posts: 58454
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another part of the Java Tutorial you should look at tells you about the Collections framework. Look particularly at the two sections about Sets.
 
Sheriff
Posts: 21291
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Steve: TreeNode, MutableTreeNode and DefaultMutableTreeNode are just great for any tree structure, not just in user interfaces.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!