You're comparing the index of last character in the string to the required character, instead of the last character itself, which you can access with charAt
:
String firstName = n.getFirstName()
if (firstName.charAt(firstName.length() - 1) == c) {
i++;
}
manpreet
Best Answer
2 years ago
I have an array list with some names inside it (first and last names). What I have to do is go through each "first name" and see how many times a character (which the user specifies) shows up at the end of every first name in the array list, and then print out the number of times that character showed up.
That is the code I have. The problem is that the counter (
i
) doesn't add 1 even if there is a character that matches the end of the first name.