Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jon Bud
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
 
Steve Luke
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic