I have a String "adam levine". How to convert first letter of every word to uppercase like this "Adam Levine"?
String line = "adam levine";
line = line.substring(0, 1).toUpperCase() + line.substring(1);
System.out.println(line); // Adam levine
I have a String "adam levine". How to convert first letter of every word to uppercase like this "Adam Levine"?
String line = "adam levine";
line = line.substring(0, 1).toUpperCase() + line.substring(1);
System.out.println(line); // Adam levine
private static final Pattern bound = Pattern.compile("\\b(\\w)");
public static String titleize(final String input) {
StringBuffer sb = new StringBuffer(input.length());
Matcher mat = bound.matcher(input);
while (mat.find()) {
mat.appendReplacement(sb, mat.group().toUpperCase());
}
mat.appendTail(sb);
return sb.toString();
}