How to Iterate a String in Java

package pretechtest;
public class StringTest {
	public static void main(String[] args) {
		String str = "Hello pretech";
		for (int i = 0; i <= str.length()-1; i++) {
			System.out.println(str.charAt(i));
		}
	}
}

Output



H
e
l
l
o
p
r
e
t
e
c
h


No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts