What you forget is that Strings are immutable; if you return the same String you started with you won't see any changes. Agree that StringBuffer is a better way to alter Strings than using the String class' methods (actually you ought to be using StringBuilder). To get the return type to String all you have to do isI think some of the method names were not very well chosen; initCap does nothing which could be called "init" nor "cap."
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
That's also what org.apache.commons.lang.WordUtils.capitalize does (after the string has been lowercased first).
I recommend to familiarize yourself with the Commons Lang library, particularly the various *Utils classes. They can be huge time savers.
As an aside, instead of
it'd be better to use
There's no point in allocating a StringBuffer that is too small (and thus might need to be resized), since you already know how long the result is going to be. [ August 01, 2008: Message edited by: Ulf Dittmer ]