Algorithm/Hash
-
HashSet 개념 및 예제#1Algorithm/Hash 2021. 12. 29. 10:22
저번 시간에 이어 이번 시간에는 Set에 대하여 공부해 보았다. Set인터페이스에는 HashSet, TreeSet, LinkedHashSet이 있는데 오늘은 HashSet에 대해 공부했다. HashSet : List와 비슷한 집합의 개념이지만, 중복을 허용하지 않고 순서가 없다. -> 중복을 허용하지 않는다는 점을 이용하여 ArrayList로 복잡하게 풀 문제들을 HashSet을 이용하여 효율적으로 코딩할 수 있는 경우들이 존재한다. -> 순서가 없다는 점으로 인해 순회를 위해서는 Iterator를 사용한다. 순서가 없어서 index표현이 불가능하므로 get(index) 메소드 대신 hasNext()와 next()를 이용하여 표현을 해야한다. Iterator ir = hashSet.iterator(); ..