|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
Looping Through Arrays
Often an array is iterated through to perform some operation on each element in it. Usually a for-loop is used in such a case, but it’s also possible to use other types of loop statements as shown in the example below where a character array is looped through and each element is printed out: |
char[] letters = new char[] { 'j', 'a', 'v', 'a', 'd', 'b', '.', 'c', 'o', 'm' }; for (int i = 0; i < letters.length; i++) { System.out.print(letters[i]); } System.out.println(); //new line for (char c : letters) { System.out.print(c); } System.out.println(); //new line int i1 = 0; while (i1 < letters.length) { System.out.print(letters[i1++]); } |
They all of course produce the same result: |
javadb.com javadb.com javadb.com |
| Previous | |
Tutorial Home | |
| Do you know your Java? | |
| Take a Ten-Question-Java-Quiz! | |
Search for code examples on this site
