I am trying to get two string firstName and lastName which is fully in uppercase and tring to convert all the characters except the first one in lowercase and concatenate the resultant strings.
firstname=”TOM”;
lastName=”HARRIS”;
Output is : Tom Harris
I achieved it by doing:
String name =
firstName.substring(0,1).toUpperCase()
+ firstName.substring(1).toLowerCase()
+ " "
+ lastName.substring(0,1).toUpperCase()
+ lastName.substring(1).toLowerCase();
but is there any other way of doing ? a more efficient way ?
Yes, you can use the method
WordUtils.capitalizeFully()from Apache Commons Lang: