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.
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.
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;
}