Monday, October 6, 2008

Get the Alphabet with Java!

This may be an embarrassing thing to admit, but I was momentarily stumped this morning when I had a need to iterate over the English alphabet with Java 1.5 ... I've been a Sun Microsystems Certified Java Programmer for 3 years now, yet this little thing got me!

Well, here's my solution, which I'm posting up now in hopes that someone with the same need may do a google search and find this post =)

char letter;
for (letter='a'; letter <= 'z'; letter++) { System.out.println( letter ); }


Simple, right!?

If you find this helpful, please leave a comment and let me know!

11 comments:

Unknown said...

This post will help me so much ... I am in almost the same situation as yours ...

Thanks.

Aaron said...

Yes man,

this is helpful :-)

Thanks!

Anonymous said...

thanks a lot!

Unknown said...

Thank you

foot prints in the sand said...

nice.. :) thx I did find it when looking for it.

SACINTHA said...

I had this when I needed it :)

Tony said...

Very helpful, you did the right thing in sharing... :)

Сергей said...

Thanks! =)
This is very helpful!

Antoine said...

Wow.. I have the same need, thanks!))

Casey Wise said...

Nice and simple, thank you for sharing!

Unknown said...

nice just what I needed, btw you can put the datatype declaration of letter within the loop's definition.

for(char letter... )