How to iterate through each characters of a string in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "java c c++";
 
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            System.out.print(ch + " ");
        }
    }
}
 
 
 
 
/*
run:
   
j a v a   c   c + + 
 
*/

 



answered Jan 20, 2022 by avibootz
edited Nov 3, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "java c c++";
 
        for (char ch : str.toCharArray()) {
            System.out.print(ch + " ");
        }
    }
}
 
 
 
 
/*
run:
   
j a v a   c   c + + 
 
*/

 



answered Nov 3, 2023 by avibootz

Related questions

1 answer 167 views
1 answer 180 views
1 answer 168 views
1 answer 199 views
1 answer 216 views
...