0

Is capitalize is not exist in java Showing error ?

public static void main(String[] args) { String str="sachin"; System.out.print(str.capitalize()); }

16th Apr 2021, 12:20 PM
Sachin Saxena
Sachin Saxena - avatar
4 Answers
+ 2
String class dose not has capitalize() method in Java like in Python. You can use: str.substring(0,1).toUpperCase()+str.substring(1)
16th Apr 2021, 12:45 PM
Amelia Voicu
Amelia Voicu - avatar
+ 4
You mean toUpperCase() ? str.toUpperCase() returns "SACHIN".
16th Apr 2021, 12:23 PM
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ
ä½ ēŸ„é“č¦å‰‡ļ¼Œęˆ‘也ę˜Æ - avatar
+ 2
I searched using google on "how to capitalize a word in java" But i see no method such as "capitalize", the only one i see is "toUpperCase"
16th Apr 2021, 12:24 PM
Abhay
Abhay - avatar
0
In JavaScript, we have a method called toUpperCase(), which we can call on strings, or words. As we can imply from the name, you call it on a string/word, and it is going to return the same thing but as an uppercase.
11th Jan 2023, 7:12 AM
Mike Clark
Mike Clark - avatar