On Wed, 31 Jan 2007 21:34:26 -0800, Michael Rauscher <>
wrote:
> cp schrieb:
>
>> Oh and you should really consider replacing the if x || y || z.... with
>> a switch. It clutters the code otherwise.
>In fact, I'd replace the whole if/switch thing with a simple
>
> String vowels = "aAeEoOuU";
And sometimes i?
I'd also declare it like this:
final String VOWELS = "aeiouAEIOU";
> if ( vowels.indexOf(pos) != -1 )
[sNip]
The reason I'd re-order the variables to begin with lower-case is for
efficiency since words are almost always mostly made up of combinations of
lower-case letters, but of course the application of this must also be
considered. Anyway, by placing the more commonly used variations first,
fewer iterations by the String.indexOf() method are required, and the
application works just a tiny bit faster as a result.
Now, with that in mind, if this little search is being used repeatedly in
a loop, then the benefits of such optimizations become more clear. With
regards to optimization, one may wish to also investigate the possibility
that "e" may be more common than "a" or that some other order would be
better suited.
--
Randolf Richardson - kingpin+
The Lumber Cartel, local 42 (Canadian branch)
http://www.lumbercartel.ca/