title: How to count the number of occurrences of words in a text
body: <p>I am working on a project to write a program that finds the 10 most used words in a text, but I got stuck and don't know what I should do next. Can someone help me please?</p>
  
  <p>I came this far only:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.List;
  import java.util.Scanner;
  import java.util.regex.Pattern;
  
  public class Lab4 {
      public static void main(String[] args) throws FileNotFoundException {
          Scanner file = new Scanner(new File("text.txt")).useDelimiter("[^a-zA-Z]+");
          List&lt;String&gt; words = new ArrayList&lt;String&gt;();
          while (file.hasNext()){
              String tx = file.next();
              // String x = file.next().toLowerCase();
              words.add(tx);
          }
          Collections.sort(words);
          // System.out.println(words);
      }
  }
  </code></pre>