I want to capitalize the first letter of all the words in a phrase EJ:
hello world
And the expected response is:
Hello World
I'm using java and I have not managed to generate a method that can do it.
I want to capitalize the first letter of all the words in a phrase EJ:
hello world
And the expected response is:
Hello World
I'm using java and I have not managed to generate a method that can do it.
public static String convierte(String string) {
if (string == null) {
return null;
}
StringBuilder builder = new StringBuilder();
StringTokenizer st = new StringTokenizer(string," ");
while (st.hasMoreElements()) {
String ne = (String)st.nextElement();
if (ne.length()>0) {
builder.append(ne.substring(0, 1).toUpperCase());
builder.append(ne.substring(1).toLowerCase()); //agregado
builder.append(' ');
}
}
return builder.toString();
}