collection 인터페이스 전체구조를 보려면 여기를 참고하자
https://s3.ap-northeast-2.amazonaws.com/opentutorials-user-file/module/516/2164.gif << 생활코딩꺼
연한파란색 -인터페이스 // 진한파랑색 - 클래스
1)iterator : 반복자 (컨테이너 값 하나씩 꺼내서 하나하나 처리 할 수 있도록 하는 역할)


hasNext : boolean타입으로 반환 (true or false)
next: 값을 리턴해서 가져온다
즉 hi안에는 123이 들어있는데 next실행되면서 123 -> 23 -> 3 -> 값없으면 hasnext(false)로 while문은 끝난다
*ArrayList로 바꿔도 오류발생하지 않는다 why?
-====> hashset이나 arraylist는 둘다 collection인터페이스를 구현하고 iterator라는 공통적인 api가 존재해서

collection을 써도 괜찮다 (iterator라는 공통적인 api가 존재해서)
'JAVA > ★객체지향' 카테고리의 다른 글
Collections framework: Collections의 사용법과 정렬 (0) | 2023.03.18 |
---|---|
Collections framework -Map (0) | 2023.03.18 |
Collections framework List와 Set의 차이점 (0) | 2023.03.15 |
Collections framework : ArrayList의 사용법 (0) | 2023.03.15 |
collections framework 전체적인 구성 (0) | 2023.03.15 |