图片经典三级电影
java8模范中list王人集去重数据,一般通过stream的distinct模范。然则distinct不够天真,那么该何如搞定呢?
性交视频1、自界说去重函数
public static <K,T>Predicate<K> distinctPredicate(Function<K,T>function){ ConcurrentHashMap<T,Boolean> map=new ConcurrentHashMap<>(); return t->null == map.putIfAbsent(function.apply(t),true); }
2、诳骗示例
创建实体类
@AllArgsConstructor @Data class Student{ private String name; private Boolean sex; private Integer age; private Double height; private LocalDate birthday; }
创建测试数据,以名字惟一去掉重迭数据。
List<Student> studentList = new ArrayList<>(); // 添加测试数据,请不要纠结数据的严谨性 studentList.add(new Student("张三", true, 18, 1.75, LocalDate.of(2005, 3, 26))); studentList.add(new Student("李四", false, 16, 1.67, LocalDate.of(2007, 8, 30))); studentList.add(new Student("王五", true, 23, 1.89, LocalDate.of(2000, 1, 16))); studentList.add(new Student("麻六", false, 27, 1.75, LocalDate.of(1996, 9, 20))); studentList.add(new Student("张三", false, 30, 1.93, LocalDate.of(1993, 6, 19))); studentList = studentList.stream().filter(distinctPredicate(Student::getName)).collect(Collectors.toList()); log.info(studentList.toString());
打钤记载经典三级电影
[Student(name=张三, sex=true, age=18, height=1.75, birthday=2005-03-26), Student(name=李四, sex=false, age=16, height=1.67, birthday=2007-08-30), Student(name=王五, sex=true, age=23, height=1.89, birthday=2000-01-16), Student(name=麻六, sex=false, age=27, height=1.75, birthday=1996-09-20)]本站仅提供存储作事,通盘推行均由用户发布,如发现存害或侵权推行,请点击举报。