去重:去除数据
中重复的数据
public class Map_offRepetition {
public static void main(String[] args) {
Integer[] nums = new Integer[]{1, 1, 1, 1, 2, 1, 2, 3, 3, 3, 5, 5, 4, 5, 4};
Repetition repetition = new Repetition();
repetition.offRepetition(nums);
}
上面是测试:
//--------------
下面是对"去重"封装的方法:
static class Repetition {
public void offRepetition(Integer[] nums) {
List list = new ArrayList<>();
Map<Integer, Object> objectObjectMap = new HashMap<>();
for (Integer number : nums) {
objectObjectMap.put(number, true);
}
Set set = objectObjectMap.keySet();
Iterator iterator = set.iterator();
while ((iterator.hasNext())) {
list.add(iterator.next());
}
System.out.println(list);
}
}
}