title: Use StringTokenizer to count frequency of each word
body: <p>I have few questions about my assignment.</p>
  
  <p>The assignment is to let user enter a sentence, and the program counts each word's frequency, when user enters an empty string, quit the program. Also, the program is case sensitive. For example, <strong>Apple is an apple is a phone</strong>, the result is that <strong>Apple-1; is-2; an-1; a-1; phone-1</strong>. Here is my code:</p>
  
  <pre><code>  public static void main(String[] args)
    {
       while (true)
        {
          System.out.println("Enter a sentence:");
          Scanner keyboard = new Scanner(System.in);
          String sentence = keyboard.nextLine();
  
          if (sentence.isEmpty())      // quit the program when user enter an empty string
          {
              break;
          }
          else
          {
             StringTokenizer st = new StringTokenizer(sentence);
  
             while (st.hasMoreTokens())
              {
               List&lt;String&gt; sentenceElement = new ArrayList&lt;String&gt;();
               sentenceElement.add(st.nextToken());
              }
  
              System.out.println(sentenceElement);
          }
    }
  </code></pre>
  
  <p>I have few questions.</p>
  
  <ol>
  <li>I try to save all tokens into an array called sentenceElement, and try to output, but failed. The compiler shows </li>
  </ol>
  
  <blockquote>
    <p>error: cannot find symbol
                System.out.println(sentenceElement);</p>
  </blockquote>
  
  <ol start="2">
  <li>How can I count the frequency of each word?</li>
  </ol>
  
  <p>Thank you so much, and I really appreciate your answers and solutions.</p>