title: How to print a Trie in Java?
body: <p>I have a trie implementation and I want to print my trie out so I can see what's in it. Preferable in a depth first traversal so the words actually make sense. Here is my code:</p>
  
  <pre><code>package trie;
  
  public class Trie {
      public TrieNode root;
  
      public Trie(){
          root = new TrieNode();
      }
  
      /*
      public Trie(char c){
          TrieNode t = new TrieNode(c);
          root = t;
      }*/
  
      public void insert(String s, int phraseNb){
          int i = 0;
          TrieNode node = root;
          char[] string = s.toCharArray();
          TrieNode child = null;
  
          while(i &lt; string.length){
              child = node.getChild(string[i]);
              if(child == null){
                  child = new TrieNode(string[i]);
                  node.addChild(child);
              }
              else{
                  node = child;
              }
              i++;
          }
  
          node.endOfWord();
          node.setNb(phraseNb);
      }
  
      public int[] search(char[] c){
          TrieNode node = root;
          for(int i = 0; i &lt; c.length-1; i++){
              node = root;
              int s = 0;
              while(i+s &lt; c.length){
                  TrieNode child = node.getChild(c[i + s]);
                  if(child == null){
                      break;
                  }
                  if(child.isWord()){
                      return new int[] {i, s+1, node.getNb()};
                  }
                  node = child;
                  s++;
              }
          }
          return new int[] {-1, -1, -1};
      }
  
      public void print(){
  
      }
  }
  
  package trie;
  
  import java.io.*;
  import java.util.*;
  
  public class TrieNode {
      private boolean endOfWord;
      private int phraseNb;
      private char letter;
      private HashSet&lt;TrieNode&gt; children = new HashSet&lt;TrieNode&gt;();
  
      public TrieNode(){}
  
      public TrieNode(char letter){
          this.letter = letter;
      }
  
      public boolean isWord(){
          return endOfWord;
      }
  
      public void setNb(int nb){
          phraseNb = nb;
      }
  
      public int getNb(){
          return phraseNb;
      }
  
      public char getLetter(){
          return letter;
      }
  
      public TrieNode getChild(char c){
          for(TrieNode child: children){
              if(c == child.getLetter()){
                  return child;
              }
          }
          return null;
      }
  
      public Set&lt;TrieNode&gt; getChildren(){
          return children;
      }
  
      public boolean addChild(TrieNode t){
          return children.add(t);
      }
  
      public void endOfWord(){
          endOfWord = true;
      }
  
      public void notEndOfWord(){
          endOfWord = false;
      }
  }
  </code></pre>
  
  <p>Just an explanation as to how to go about doing it or some pseudo code is all I need. Thanks for your time.</p>