Array.asList를 이용하여 간단하게 중복 제거
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | String[] test = {"1","2","3","1","2"}; System.out.println("before length=" + test.length); test = new HashSet<String>(Arrays.asList(test)).toArray(new String[0]); System.out.println("after length=" + test.length); for(String s:test){ System.out.println(s); } /* result before length=5 after length=3 1 2 3 */ | cs |
how to remove duplicate String array in java? ..
'Programming > Java' 카테고리의 다른 글
No qualifying bean of type 'org.modelmapper.ModelMapper' available: 해결방법 (0) | 2019.12.11 |
---|---|
[java/pattern] builder pattern 빌더 패턴 (0) | 2018.05.30 |
[Java] String 뒤집기 (Reverse) (0) | 2018.05.26 |
[Java8] List<Integer> -> int[] 변경방법 (0) | 2018.04.11 |
[알고리즘] 선택정렬, 버블정렬, 삽입정렬, 퀵정렬 (0) | 2017.01.31 |