How many paths are in some three? There are as many paths as many leaves - because that your code doesn't work. Code which you wrote only iterates through all nodes. But you want to print all paths from root to the leaves.
One solution is to use recursion: It starts from root and print path for every children. It look something like this
public void printPaths(Node<T> nodeOnPath, String onPath){
String nodePath = onPath + "/" + nodeOnPath.getNodeContent().toString();
if (nodeOnPath.isLeaf()){
System.out.println(nodePath);
return;
}
ArrayList<Node> children = nodeOnPath.getChildren();
for (Node<T> node : children){
printPaths(node, nodePath);
}
}
Method for printing paths I named printPaths - it takes two arguments: the firs is node nodeOnPath and second is path from root to the node nodeOnPath. At the first line of method it creates nodePath. Then check if node is leaf - if answer is yes then print nodePath and exit from the method.
In case if the node is not leaf then get all children for the node, iterate through them and for every node generate path. This part is in for each loop.
To print all paths you will call method printPaths like this
printPaths(rootNode, "");