How can I create and use tree-like data structures in Java? Are there any standard classes for this?

Luigi Viggiano

No, there's no structures to represent a Tree. You can use collections. A collection can contain more objects (leafs), and each leaf can be again a collection (node) and contain more leafs and so on...

Collection
 |
 |--Object
 |--Object
 |--Collection
 |   |--Object
 |   |--Collection
 |   |   |--Object
 |   |   |--Collection
 |   |       |-Object
 |   |       |-Object
 |   |       |-Object
 |   |--Object
 |--Object

As collection I suggest you to use an ArrayList or LinkedList (or TreeList if you want leafs ordered).
If leafs are unique inside a node, I suggest you to use instead an HashSet (or TreeSet if you want leafs ordered).

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact