java do something for each character in a string code example Example: java foreach char for (char ch: "xyz".toCharArray()) { System.out.println(ch); }