devxlogo

Loop the Characters of a String

Loop the Characters of a String

Looping the characters of a string can be done via charAt() or toCharArray() as follows:

String str = "hello world";for (int i = 0; i

Or, via toCharArray():

for(char ch: str.toCharArray()) {...}

devx-admin

Share the Post: