How to implement a tree data-structure in Java?

前端 未结 24 2458
鱼传尺愫
鱼传尺愫 2020-11-22 00:27

Is there any standard Java library class to represent a tree in Java?

Specifically I need to represent the following:

  • The sub-tree at any node can have
24条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 00:50

    There is actually a pretty good tree structure implemented in the JDK.

    Have a look at javax.swing.tree, TreeModel, and TreeNode. They are designed to be used with the JTreePanel but they are, in fact, a pretty good tree implementation and there is nothing stopping you from using it with out a swing interface.

    Note that as of Java 9 you may wish not to use these classes as they will not be present in the 'Compact profiles'.

提交回复
热议问题