-3

how can i capitalize the last letter of a String? Is there a method in the String Class to do this?

I'm practicing with some exercise, and i was asked to do this with a method.

Juza
  • 17
  • 4
  • 2
    An idea might be to search for capitalizing the *first* letter. Then look what you have to modify. – Willem Van Onsem Mar 31 '17 at 15:23
  • Yeah, good idea! I'll check it, thank you! – Juza Mar 31 '17 at 15:24
  • Whoops, misread it as JavaScrupt – Isaiah Mar 31 '17 at 15:27
  • Your requirement is vague: do you mean capitalize the last character in the string (if that happens to be a letter), or find the last letter in the string and capitalize it. For instance, should `"az0"` remain as `"az0"`, or should it become `"aZ0"`? – Andy Turner Mar 31 '17 at 15:40

1 Answers1

0

No there is not. but you can write one yourself.

 public String capitalizeLastLetter(String word) {
    //null check
    int length = word.length();
    String capitalizedLetter = word.substring(length - 2, length - 1).toUppercase();
    return word.substring(0, length - 2) + capitalizedLetter;
}
Zildyan
  • 1,261
  • 9
  • 11