Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate through a String [duplicate]

Tags:

java

string

loops

How can I iterate through a string in Java?

I'm trying to use a foreach style for loop

for (char x : examplestring) {
    //action
}
like image 942
muttley91 Avatar asked Sep 26 '10 18:09

muttley91


1 Answers

If you want to use enhanced loop, you can convert the string to charArray

for (char ch : exampleString.toCharArray()) {
  System.out.println(ch);
}
like image 117
surajz Avatar answered Oct 10 '22 01:10

surajz