Languages
[Edit]
EN

Java - iterate through string

0 points
Created by:
Burhan-Boyce
458

In this article, we would like to show you how to iterate through string in Java.

Quick solution:

 

1. Using for loop with String charAt()

Edit

In this example, we iterate through the text string and print each character.

Output:

2. Using String toCharArray()

Edit

In this example,  we use String toCharArray() method to convert text String to the characters array. Then we use enhanced for-loop to iterate through the array.

Output:

3. Using String split()

Edit

In this example,  we use String split() method to convert text String to the letters array. Then we use enhanced for-loop to iterate through the array.

Output:

4. Using Iterator

Edit

In this example, we use StringCharacterIterator class to iterate through the text string.

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - String (popular problems)

Java - iterate through string
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join