0

I have been working on a program that is going to read two letters that you input and then delete them based on their starting letter.

My current problem is trying to figure a way how to read the starting letter no matter whether you enter lowercase or uppercase.

My current code:

for (int i = 0; i < list.size(); i++) {
        if (list.get(i).startsWith(first)) {
            start = i;
            break;
        }
    }
    for (int x = list.size() - 1; x > 0; x--) {
        if (list.get(x).startsWith(second)) {
            end = x;
            break;
        }
    }

ArrayList contains case sensitivity checks the whole word I need to only check the first letter and I can't find anything after looking for two days on something to help me.

Rylan Howard
  • 53
  • 11

1 Answers1

0

If you need to check for just first character of both strings, you can use charAt() as below else you need to convert both strings to either Upper or Lowercase

Character.toLowerCase(list.get(i).charAt(0)) == Character.toLowerCase(first.charAt(0))

or

If you need to check for more than one character use string method toLowerCase() as below

list.get(i).toLowerCase().startsWith(first.toLowerCase())
Munesh
  • 1,509
  • 3
  • 20
  • 46