Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Actually, substring() is a bit more intelligent than that. All the Strings created using substring() will use the same underlying character array (since Strings are immutable in Java). A new String container will still be created for each substring, which still makes the loop more efficient.

Ooo, darn meddling kids. You got me. :)
 
Look again. You created lots of Character objects, but I didn't create any. The character utility functions are static for exactly that reason. Character.isLetter(x) is the way to test. Even if you didn't have that, you can still use comparison operators on primitive types:

Code:
if((x >= 'A' && x <= 'Z') || (x >='a' && x <= 'z')) {...}

<homer>Doh!</homer> Sorry! Spent too long at work looking, mostly, at Java code! I don't personally like the primitive comparisons. The assumption there is that we are using the "standard" 26 character alphabet. I'm pretty sure that would not count é as a letter, but isLetter() would.
 
Slight efficiency losses aside, recursion still strikes me as the most elegant and readable solution-then again, my current recursion tendencies may largely be that I've been doing Lisp recently. ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.