Answers for "iterate each char in string in java"

0

iterate each char in string in java

class Main {
  public static void main(String[] args) {

    // create a string
    String name = "Programiz";

    System.out.println("Characters in " + name + " are:");

    // loop through each element
    for(int i = 0; i<name.length(); i++) {

      // access each character
      char a = name.charAt(i);
      System.out.print(a + ", ");
    }
  }
}
Posted by: Guest on June-03-2021
0

iterate each char in string in java

class Main {

  public static void main(String[] args) {

    // create a string
    String name = "Programiz";

    System.out.println("Characters in string \"" + name + "\":");

    // loop through each element using for-each loop
    for(char c : name.toCharArray()) {

      // access each character
      System.out.print(c + ", ");
    }

  }
}
Posted by: Guest on June-03-2021

Code answers related to "iterate each char in string in java"

Browse Popular Code Answers by Language