💡Set 개념 정리
📘 특정한 값들을 저장하는 추상자료형
Set 특징
기본 메서드
set.add("A") : 요소 추가
set.remove("A") : 요소 삭제
set.contains("A") : 포함 여부 확인
set.size() : 크기 반환
set.isEmpty() : 비어있는지 확인
set.clear() : 모든 요소 삭제
for(String s : set) : Iterator 반환

HashSet
Set<String> set = new HashSet<>();
set.add("A");
set.add("B");
set.add("A"); // 중복 X

LinkedHashSet
Set<String> set = new LinkedHashSet<>();
set.add("B");
set.add("A");
set.add("C");
// 순서: B → A → C

3. TreeSet
- 정렬된 상태로 저장
- 기본 오름차순 정렬
- 정렬된 Set이 필요할 때 사용
```java
Set<Integer> set = new TreeSet<>();
set.add(3);
set.add(1);
set.add(2);
// 자동 정렬: 1, 2, 3
first() // 가장 작은 값
last() // 가장 큰 값
higher(x) // x보다 큰 값 중 가장 작은 값
lower(x) // x보다 작은 값 중 가장 큰 값
```
Set<String> set = new HashSet<>();
// 추가
set.add("Apple");
set.add("Banana");
// 중복 추가 (무시됨)
set.add("Apple");
// 삭제
set.remove("Banana");
// 포함 여부
System.out.println(set.contains("Apple")); // true
// 크기
System.out.println(set.size()); // 1
// 비어있는지
System.out.println(set.isEmpty()); // false
// 전체 삭제
set.clear();
// 순회
set.add("A");
set.add("B");
for(String s : set){
System.out.println(s);
}