Home » Tip Bank » Java
  • Comment on this Article
Language: Java
Expertise: Intermediate
Oct 15, 2019
  • facebook
  • twitter
  • in
  • Email

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

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<str.length(); i++) {
char ch = str.charAt(i);
...
}

Or, via toCharArray():

for(char ch: str.toCharArray()) {
...
}
Octavia Anghel
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
htmlandcssbook.com
enable-javascript.com