This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 4168
    
  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: 4168
    
  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: 38075
    
  22
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: 19656
    
  18

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
 
jQuery in Action, 2nd edition
 
subject: Does java have a class that has a tree data structure?
 
Similar Threads
Barn Burning Patterns
WA #2 ..... word association
Need help understanding generics.
How low level do YOU code ?
Jboss in Action question: migration from other Application Servers