Count same lines in a file, JAVA
<p>I have a text file which has lines of animals, who occur on this list from 1 to n times. I need to read this text file, count all the separate animal occurences, sort them from highest to lowest and put them in a jtable.</p>

<p>For example, the text file looks like this:</p>

<pre><code>dog
sheep
cat
horse
cat
tiger
cat
cat
tiger
</code></pre>

<p>I need to count all the same occurences like so:</p>

<pre><code>dog 1
sheep 1
cat 4
horse 1
tiger 2
</code></pre>

<p>And then sort them from highest to lowest and somehow put them into a table, so that would be:</p>

<pre><code>Animal name: count
cat          4
tiger        2
dog          1
sheep        1
horse        1
</code></pre>

<p>So, for now my specific question is how can i count the matches for all the separate animals?</p>

<p>Thanks for the help!</p>

<hr>

<h3>EDIT</h3>

<p>The answer provided by Vishal Kamat, has worked, my animals and their occurences have been counted with this code:</p>

<p><a href="https://stackoverflow.com/questions/31288274/java-hashmap-word-count-from-a-text-file">java hashmap word count from a text file</a></p>

<p>Now, I just need to put all this information to a new jtable</p>