You have two main options:
String myString = "ABCD"; for (char c : myString.toCharArray()) { System.out.println("Characer is " + c); } for (int i = 0; i < myString.length(); i++) { System.out.println("Character is " + myString.charAt(i)); }
The first loops through an array of characters, and the second using a regular indexed loop.
However, Java does support characters such as '\ n' (newline). If you want to check for the presence of this character, you can use the indexOf ('\ n') method, which will return the position of the character, or -1 if it cannot be found. Be warned that the characters "\ n" are not required to end the line, so you cannot rely solely on this.
Strings in Java do not have a NULL terminator, as in C, so you need to use the length () method to find out how many lines a string is.
Ewald source share