Welcome to the Ranch.
Ok let me guess why you have 2 maps. The
word map is the actual or source and the word2 map is the lowercase version. And let me guess why you get the NullPointerException... either the words or word2 is null for the else if block.
Anyway since you are doing a "word counter" you really need to define what is a "word". Suppose I have the line or sentence: "Today is sunny." This line has 3 words. So if I assume you put the items into the map correctly
you should get:
And when you fetch say "is" you get 2.
But I personally think there can be 2 ways of doing this. It depends on what you really want at the end - just a number or like what you have done (matching word count to the actual word). If you just want a number - given you read a line you can simply split it using the blank or space into a
String array and return the array size. If keeping what you have done you can again return the map size.
For the other way putting the words into the map is the key. Once you can try looping the keys and see if it is want you want.