This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Does java have a class that has a tree data structure? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does java have a class that has a tree data structure?" Watch "Does java have a class that has a tree data structure?" New topic
Author

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

Jon Bud
Greenhorn

Joined: Jan 29, 2009
Posts: 12
If it does, what is the import statement required, constructor parameters ect. Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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

Joined: Oct 13, 2005
Posts: 38515
    
  23
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

Joined: Oct 27, 2005
Posts: 19684
    
  20

I agree with Steve: TreeNode, MutableTreeNode and DefaultMutableTreeNode are just great for any tree structure, not just in user interfaces.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Does java have a class that has a tree data structure?