Answers for "iterator string java for loop"

12

java iterate over a string

String scientistName = "Isaac Newton";
 
for (int i = 0; i < scientistName.length(); i++) {
    System.out.print(scientistName.charAt(i) + " "); // I s a a c   N e w t o n
}

//*********************************************************
// you can cast a string into a char[]
String str = "strings are not primitive types!";
 

for (char ch : str.toCharArray()) {
    	System.out.print(scientistName.charAt(i) + " ");
    }
}
Posted by: Guest on March-20-2020
1

java go troght loop object

import java.util.List;
import java.util.ArrayList;

List<String> list = new ArrayList<>();

list.add("first");
list.add("last");

for(String s : list) {
  if (s != null) {
    //do whaterver wanted
    // example:
    System.out.println(s);
  }
}
Posted by: Guest on June-30-2020

Code answers related to "iterator string java for loop"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language