去除重复元素/重复对象
使用去重API
//注意:Student对象需要重写equals方法和hashcode方法
public static void main(String[] args) {
ArrayList<Student> list = new ArrayList<>();
list.add(new Student("张三", 19, "杭州"));
list.add(new Student("张三", 19, "杭州"));
list.add(new Student("李四", 18, "海口"));
List<Student> studentList = list.stream().distinct().collect(Collectors.toList());
System.out.println(studentList);
}
结果: