Convert A String To Proper Case In Java

Converting a string to proper case in Java.
e.g. convert “roBErT” to “Robert”.

Example code:

String forename = “roBErT”;
String forenameforenameInitial = “”;

forename = forename.toLowerCase();
forenameInitial = forename.substring(0, 1).toUpperCase();
forename = forenameInitial + forename.substring(1,forename.length());

System.out.println(forename);

The string vaiable forename now has a value of  “Robert”.

Advertisements

One thought on “Convert A String To Proper Case In Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s