Converting Strings to Title case

What is the best and most efficient way to convert Strings to title case?  I know java.lang.String has methods to convert to UpperCase and to LowerCase, but I am surprised that there is nothing to convert to TitleCase.
bjgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

imladrisCommented:
Could you explain what you mean with Title case? The Latin character set has two representations for each character, one is lower case (a) one is uppercase (A). What is Title case?
0
bjgAuthor Commented:
Where the first letter of the String is in upper case and the rest are in lower case.  java.lang.Character has a method called isTitleCase().
0
imladrisCommented:
There is no method provided for that. You would have to write it yourself. Something along the lines of:

String tgt="THIS IS A TEST";
StringBuffer s=new StringBuffer(tgt.toLowerCase());
boolean raise=true;
for(int i=0; i<s.length(); ++i)
{   if(raise && !Character.isSpace(s.charAt(i)))
    {   s.setCharAt(i,Character.toUpperCase(s.charAt(i)));
        raise=false;
    }
    else if(!raise && Character.isSpace(s.charAt(i)))
    {   raise=true;
    }
}
String ns=new String(s);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.