HashSet<String> hs = new HashSet<String>();
hs.add("문자열1");
hs.add("문자열2");
hs.add("문자열3");
hs.add("문자열3");
//출력 순서
Iterator<String> it = hs.iterator(); //1. Iterator 인터페이스 생성
//2. while문으로 출력. 조건 it.hasNext()(리턴타입: boolean)
while(it.hasNext()){ //다음 값이 존재하면 hasNext가 true를 반영해 계속 출력
String s = it.next(); //3. it.next()다음번 요소를 리턴
System.out.print(s+" ");
}
출력예시: 문자열2 문자열1 문자열3
->순서대로 나오지 않고, "문자열3"은 중복이라 하나만 출력된다.