How to get recursively get all leaves of a Tree Structure in Java
<p>I have a Database Table of a Tree Nodes as below. I want to make a ArrayList in Java out of these Tree Nodes. the Arraylist will recursively fetch all the Tree Nodes in a Recursive Format in Java. </p>

<p>Input:</p>

<p>Database Table</p>

<pre><code>Name            ID      Parent_ID
Parent          1   
Child-1         2           1
Child-1.1       3           2
Child-1.1.1     4           3
Child-2         5           1
Child-3         6           1
Child-1.1.1.1   7           4
Child-1.2       8           2
</code></pre>

<p>I want to make an ArrayList of the above table in the below Java format where Sub is list of the Child Nodes, if no Child Node then Sub is Null.</p>

<pre><code>public class Node {

    private String id;
    private String name;
    private String type;
    private String value;
    private List&lt;Node&gt; sub;
}
</code></pre>

<p>Output:</p>

<ol>
<li>Parent

<ul>
<li>Child-1

<ul>
<li>Child-1.1

<ul>
<li>Child-1.1.1

<ul>
<li>Child-1.1.1.1</li>
</ul></li>
</ul></li>
<li>Child-1.2</li>
</ul></li>
<li>Child-2</li>
<li>Child-3</li>
</ul></li>
</ol>

<p>Can someone please help in creating a recursive function in Java to implement the above.</p>