title: String Tokenizer
body: <p>Can anybody help me understand how this string tokenizer works by adding some comments into the code? I would very much appreciate any help thanks!</p>
  
  <pre><code>public String[] split(String toSplit, char delim, boolean ignoreEmpty) {
  
      StringBuffer buffer = new StringBuffer();
      Stack stringStack = new Stack();
  
      for (int i = 0; i &lt; toSplit.length(); i++) {
          if (toSplit.charAt(i) != delim) {
              buffer.append((char) toSplit.charAt(i));
          } else {
              if (buffer.toString().trim().length() == 0 &amp;&amp; ignoreEmpty) {
              } else {
                  stringStack.addElement(buffer.toString());
              }
              buffer = new StringBuffer();
          }
      }
  
      if (buffer.length() !=0) {
          stringStack.addElement(buffer.toString());
      }
  
      String[] split = new String[stringStack.size()];
      for (int i = 0; i &lt; split.length; i++) {
          split[split.length - 1 - i] = (String) stringStack.pop();
      }
  
      stringStack = null;
      buffer = null;
  
  //        System.out.println("There are " + split.length + " Words");
      return split;
  }
  </code></pre>