0

Give me solution in java: I have one string "i am Learning sololearn", I want to make first letter of each word in uppercase.

please give me.different type of solution.

15th Jul 2019, 6:47 AM
Gaurav Shinde
Gaurav Shinde - avatar
2 Réponses
+ 2
split the string word by word, change the first letter of each word to uppercase, merge them back to string
15th Jul 2019, 7:06 AM
Taste
Taste - avatar
+ 2
public class Program { public static String capitalized(String s){ StringBuilder sb = new StringBuilder(); for(String w : s.split(" ")) { String firstLetter = w.substring(0,1); String rest = w.substring(1); sb.append(firstLetter.toUpperCase() + rest.toLowerCase() + " "); } return sb.toString().trim(); } public static void main(String[] args) { System.out.println(capitalized("i am LEArning soLOlearn.")); } }
15th Jul 2019, 7:57 AM
Jake
Jake - avatar