Java foreach statement (advanced for iteration statement) 자바 향상된 for문 문법
Main function process
//Process
//1. Make new integer list for sample
//2. Iterate using normal for statement (printout)
//3. Iterate using foreach statement (printout)
//4. Finish
//처리과정
//1. 확인할 샘플 정수리스트를 만든다.
//2. 일반 for문을 사용하여 출력해본다.
//3. foreach문을 사용하여 출력해본다.
//4. 끝낸다.
Example code below
public class TestForeach {
public static void main(String args[]) {
// Initialize sample list
List<Integer> testList = new ArrayList<>();
for (int i = 0; i < 3; ++i)
{
testList.add(i+1);
}
//check using for statement
for (int i = 0; i < testList.size(); ++i)
{
System.out.println(testList.get(i));
}
//check using foreach statement
for (Integer val : testList)
{
System.out.println(val);
}
}
}
Something you might like...
2018/11/17 - [Programming/C++] - How to initialize vector in C++ STL (Standard Template Library), STL 벡터 초기화 방법
2018/11/17 - [Programming/C++] - C++ How to convert string to integer in C++, string 에서 int 변환하는 방법, Easiest way to convert string to int.
2018/11/17 - [Programming/C++] - C++ How to convert integer to string in C++, int 에서 string 변환하는 방법, Easiest way to convert int to string.
2018/11/20 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #31 depositProfit. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/11/18 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #30 circleOfNumbers. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/11/17 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #29 chessBoardCellColor. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/11/15 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #28 alphabeticShift. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
2018/11/15 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #27 variableName. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar