How do I apply the for-each loop to every character in a String in Java?

Posted by oxinabox.ucc.asn.au on Stack Overflow See other posts from Stack Overflow or by oxinabox.ucc.asn.au
Published on 2010-03-16T01:53:56Z Indexed on 2010/05/04 2:18 UTC
Read the original article Hit count: 325

Filed under:
|
|
|
|

So I want to iterate for each character in a string.

So I thought:

for (char c : "xyz")

but I get a compiler error:

StackCharTester.java:20: foreach not applicable to expression type

How can I do this?

© Stack Overflow or respective owner

Related posts about foreach

Related posts about java