1. Engineering
  2. Computer Science
  3. case insensitivity in java in my program im reading contents...

Question: case insensitivity in java in my program im reading contents...

Question details

Case insensitivity in Java

In my program, I'm reading contents of a file and checking to see if each character is the same as a character specified by the user. However, the program is required to be canse insensitive, so that if the user wants to see how many "a" are in the file, each iteration of "A" is also counted. I have the following line where I'm stuck:

if(line.charAt(i).equalsIgnoreCase(character))

I receive an error that says "cannot be dereferenced" (I'm assuming because charAt(i) isn't a string?)

If I do if(line.charAt(i)==character), it works but isn't case insensitive. How would I manipulate this so that it IS case insensitive?

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution