String 배열 중복제거

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? ..