JAVA
for each
seoca
2019. 7. 13. 06:19
for-each
for (Type obj : Collection) {...}
example
for (CustomInfo c : customManagers) {
System.out.println(c.toString());
}
works only if the collection holds elements of type Type.
public class Main{ public static void main(String[] args) { int[] arr = new int[]{ 1,2,3,4,5 }; //for-each. normally used for iterating Arrays or Collection
for (int i : arr) { System.out.print(i); //12345 } System.out.println(""); //normal for loop
for (int i = 0; i<arr.length; i++) { int var = arr[i]; System.out.print(var); //12345 } } }
|