Stream中的collectingAndThen去重排序(取每组日期最大)

本文展示了如何使用Java的StreamAPI对学生成绩列表进行去重,按照姓名降序排序,并利用递归计算阶乘的方法。
摘要由CSDN通过智能技术生成

package com.itheima.method2;

import java.util.*;
import java.util.stream.Collectors;

import static com.itheima.test.Test1.printArray;

public class Test007 {
    public static void main(String[] args) {

                //System.out.println(chengji(new int[]{-8,-1,1, 3, 4}));
                // 2.3 数据去重
                List<Student> functionList = Arrays.asList(
                        new Student(123, "分组1", "2019-12-11"),
                        new Student(124, "分组1", "2019-12-23"),
                        new Student(125, "分组2", "2020-12-11"),
                        new Student(126, "分组2", "2020-12-23"));
                ArrayList<Student> collect = functionList.stream().
                        sorted(Comparator.comparing(Student::getAddress).reversed())
                        .collect(Collectors.
                        collectingAndThen(Collectors.toCollection(() ->
                                new TreeSet<>(Comparator.comparing(Student::getName))), ArrayList::new));

                System.out.println(collect);

    }

  public static int jieCheng(int n){
        if (n==1){
            return 1;
        }
       return n*jieCheng(n-1);
  }
}

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值