Find out words occurrences in a file

In the previous post, we have seen how to find common elements among 2 unsorted arrays. In this post, we will see how to get the count of same word occurrences in a file.

Find out words occurrences in a file:

There are few steps given below that need to be followed.

  • Create a object for file
  • Read it using Buffered Reader
  • Create a Map of String and Integer as key and value respectively
  • Keep increasing the counter if key matches more than once
  • Display keys and their values
Output:

is– 3
are– 2
how– 2
your– 1
doing– 1
book– 1
you– 2
house– 1
dog– 1
my– 2
this– 3
Find common elements among two unsorted arrays
Database connection in Java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *