-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathShunwang.java
More file actions
31 lines (29 loc) · 682 Bytes
/
Shunwang.java
File metadata and controls
31 lines (29 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package other;
import java.util.HashSet;
import java.util.Set;
/**
* 顺网科技-去除数组中重复元素
*
* @author 刘壮飞
* https://github.com/zfman.
* https://blog.csdn.net/lzhuangfei.
*/
public class Shunwang {
public static void main(String[] args){
int[] arr={
1,2,3,4,10,8,5,1,2
};
Set<Integer> set=new HashSet<>();
for(Integer val:arr){
set.add(val);
}
int[] newArr=new int[set.size()];
int i=0;
for(Integer val:set){
newArr[i++]=val;
}
for(int t=0;t<newArr.length;t++){
System.out.print(newArr[t]+" ");
}
}
}