Skip to content

Convert String to title case in Java example

Convert String to title case in Java example shows how to convert string to title case in Java using various approaches to convert string to camel case or proper case.

How to convert String to title case in Java?

There are various approaches to convert as given below.

1) Convert string to title case using the split and substring methods

Split the String by space, for each part make the first letter uppercase and rest characters to lower case, append the part to the StringBuilder (or StringBuffer) object followed by a space. Finally, convert the StringBuilder to String object and trim the last unwanted space.

Output

2) Using the char array and Character class

Instead of the substring method, you can first convert each part of the string to lower case, create a character array from the lower case part, make the first character upper case and append the character array to the StringBuilder.

Output

3) Using the Apache Commons library

If you are using the Apache Commons library, you can use capitalizeFully method of WordUtils class to convert the string.

Output

Note: If you are using Java 1.4 or lower version, use StringBuffer instead of the StringBuilder class.

This example is a part of the String in Java tutorial.

Please let me know your views in the comments section below.

About the author

2 comments

    1. Hi,
      Currently, I do not offer any courses via email, but you can bookmark the site to quickly return to it, I would also ask you to like the Facebook page where I post different examples/tutorials daily.

Leave a Reply

Your email address will not be published.