title: How to count frequency of each words in the array?
body: <p>I have a program, which users can enter a sentence, and it can split each word into an array. Also, I need to count the frequency of each words. 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>. </p>
  
  <p>Please help me solve this problem, I don't know how to count the frequency of each word. </p>
  
  <p>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);
  
          List&lt;String&gt; sentenceElement = new ArrayList&lt;String&gt;();
  
          while (st.hasMoreTokens())
          {
            sentenceElement.add(st.nextToken());
          }
  
          System.out.println(sentenceElement);
          }
    }
  </code></pre>
  
  <p>Thank you so much!!</p>