假如一个数组arr=[1,2,3,4,5,3,2,1],要求删除中重复的数字。
int arr[] = new int[]{1,2,3,4,5,3,2,1};
Set set = new HashSet();
int count = 0;
for (int i = 0; i < arr.length; i++) {
set.add(arr[i]);
}
Object array[] = set.toArray();
count = array.length;
System.out.println("不重复元素的个数:" + count);
System.out.println(set);
最后
以上就是拉长冬瓜最近收集整理的关于面试题:给定一个数组,删除其中重复数字的全部内容,更多相关面试题:给定一个数组内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复