iterating cahr array in java code example
Example 1: loop through array java
public class HelloWorld {
public static void main(String[] args) {
String[] family = new String[] {"Member1", "Member2", "Member3", "Member4", "Member5"};
for(String name : family)
{
System.out.println(name);
}
}
}
Example 2: iterator for array java
import java.util.Arrays;
import java.util.Iterator;
public class ArrayToIterable {
public static void main(String args[]){
Integer[] myArray = {897, 56, 78, 90, 12, 123, 75};
Iterator<Integer> iterator = Arrays.stream(myArray).iterator();
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}