0

Possible Duplicate:
Java tree data-structure?

Is there any Java data structure implementation similar to tree and graph?

0

2 Answers 2

4

Not in the java.util Collections API.

You can use the DefaultTreeModel from Swing for trees.

Jung is a graph framework.

Sign up to request clarification or add additional context in comments.

Comments

0

As I answered for a similar question, the Java API contains no general API for trees/graphs, since there is no unique set of features needed in every usecase. There are quite some tree/graph-like APIs for special cases, though.

And in principle it is easy to make your own graph - one could even say that every object is in fact a node in a graph, with the values of its reference type fields being the (outgoing) neighbors.

4 Comments

Not true for tree: DefaultTreeModel in Swing is stand-alone enough where you can use it without a UI.
I listed this in my linked answer, too. I don't like DefaultTreeModel, I'm even with Swing usually using my own TreeModel implementation, so I would never have the idea to use it outside of Swing.
What don't you like about it? How does yours improve on it?
DefaultTreeModel is usually too complicated, for my view, depending on what you want to do. I usually make a new model for each use case, based on the domain model (i.e. the self made object tree as mentioned in my answer) instead of some TreeNode implementation (which is the basic tree interface behind DefaultTreeModel). Of course, the javax.swing.tree package is missing an AbstractTreeModel implementing the listener stuff, which seems to lead to use DefaultTreeModel, even though it is more than needed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.