Search code examples
javalowercase

How to change string to lower case?


Trying to make it so that if the user enters any vowel capitalized, it will return true. So, that's where I added the "letter = letter.toLowerCase();" but it's not working still..

    public static boolean isVowel (String letter) {
        letter = letter.toLowerCase();
        if (letter == "a" || letter == "e" || letter == "i" || letter == "o" || letter == "u" ) {
            return true;

        } else {
            return false;
        }
    }

Solution

  • Try using if (letter.equals("a") || and so on.

    == tests the memory references of String variables, not the contents of the references.

    The equals method of the String class tests the contents of the references.