• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it does, what is the import statement required, constructor parameters ect. Thanks
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic