dotcome dotcome - 4 years ago 171
Java Question

How to upper case every first letter of word in a string, meanwhile removing eventual whitespaces in Java?

private String name;

public String getName() {
return name.replaceAll("\\s+","")
.substring(0, 1)
.toUpperCase() + name.substring(1)

Answer Source

If you want to do this with any effort, use a library like Guava.

See documentation of CaseFormat here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download