Java

Java, Iterator(반복자)

greenyellow-s 2024. 7. 30. 13:54
Iterator

 

Iterator 인터페이스는 Collection 인터페이스를 구현 및 상속한 모든 컬렉션 클래스에서 사용한다.

 

Iterator 메소드

메소드 특징
next() 다음 요소를 추출
remove() next()로 호출된 요소를 제거
hasNext() 다음 요소가 존재할 때 True 존재하지 않을 때 False 리턴

 

Iterator it = coll.iterator();

while(it.hasNext()) {
    System.out.println(it.next());
}