How can I create and use tree-like data structures in Java? Are there any standard classes for this?
Created May 8, 2012
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).