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.
2 Antworten
+ 2
split the string word by word, change the first letter of each word to uppercase, merge them back to string
+ 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."));
}
}