1class AssignmentOperator {
2 public static void main(String[] args) {
3
4 char[] vowels = {'a', 'e', 'i', 'o', 'u'};
5 // foreach loop
6 for (char item: vowels) {
7 System.out.println(item);
8 }
9 }
10}
1String[] myArray = {"Enhanced for loops", "are cool", "and save time!"};
2
3for (String myValue : myArray) {
4 System.out.println(myValue);
5}
6
7/*Result:
8Enhanced for loops
9are cool
10and save time!
11*/
1public class Test {
2
3 public static void main(String args[]) {
4 int [] numbers = {10, 20, 30, 40, 50};
5
6 for(int x : numbers ) {
7 System.out.print( x );
8 System.out.print(",");
9 }
10 System.out.print("\n");
11 String [] names = {"James", "Larry", "Tom", "Lacy"};
12
13 for( String name : names ) {
14 System.out.print( name );
15 System.out.print(",");
16 }
17 }
18}
1for (int i=0; i < array.length; i++) { System.out.println("Element: " + array[i]);}