생성자를 이용하는 방법과 copyOf를 이용하는 방법 두 가지가 있다.
1. Set -> List
- Set<String> set = new HashSet<>(list);
- Set<String> set = Set.copyOf(list); // unmodifiable, 불변객체
2. List -> Set
- List<String> list = new ArrayList<>(set);
- List<String> list = List.copyOf(set); // unmodifiable, 불변객체
'Java' 카테고리의 다른 글
[Java] 자바 Math.pow() 함수 (0) | 2025.03.05 |
---|---|
[Java] replace와 replaceAll의 차이 (0) | 2025.03.05 |
[Java] 10진수 <-> 2진수, 8진수, 16진수 변환 (0) | 2025.03.01 |
[Java] 오버로딩 성립 요건 (1) | 2025.02.21 |
[Java] 접근제어자 (0) | 2025.02.20 |