import java.util.ArrayList;
import java.util.Iterator;
public class MainRunner
{
public static void main(String[] args)
{
ArrayList<String> my_arr_list = new ArrayList<String>();
my_arr_list.add("hello");
my_arr_list.add("java");
my_arr_list.add("world!");
Iterator<String> it = my_arr_list.iterator();
// while문으로 my_arr_list의 모든 원소를 출력해봅시다.
while( it.hasNext() )
{
System.out.println( it.next() );
}
}
}
- Iterator의 it.hasNext() 메서드는 더 순회할 요소가 있는지 알 수 있다.
- Iterator의 it.next() 메서드는 다음 요소를 가지고 올 수 있다.
(본 코드와 내용은 프로그래머스 egoing 자바 자료구조 강의 내용에 포함되어 있습니다.)
'WIL(What I Learned)' 카테고리의 다른 글
원소를 무한히 저장하는 ArrayList 구현하기 (프로그래머스 자바 자료구조) (0) | 2021.08.23 |
---|---|
java ArrayList indexOf() (0) | 2021.08.23 |
What does the colon (:) operator do? (0) | 2021.08.16 |
java input (Scanner class) (0) | 2021.08.16 |
okky Spring IoC (0) | 2021.08.05 |