Map<Integer, String> lendReturnMap = lendReturnList.stream().collect( Collectors.toM

 2.

3.

package com.itheima.demo18_扩展字符串排序;

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

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

        List<Student> lendReturnList = Arrays.asList(new Student("zd", 101), new Student("zd1", 10), new Student("zd2", 102));


        Map<Integer, String> lendReturnMap = lendReturnList.stream().collect(
                Collectors.toMap(Student::getAge, Student::getName)
        );
        for (Map.Entry<Integer, String> entry : lendReturnMap.entrySet()) {
            System.out.println(entry.getKey() + entry.getValue());
        }

    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Easypoi导出list.stream().collect(Collectors.groupingBy())分组后的数据的示例代码: ```java // 定义一个Person类 public class Person { private String name; private int age; private String gender; // 构造函数、getter和setter方法省略 } // 分组并导出数据 public void exportGroupData() { // 模拟数据 List<Person> personList = new ArrayList<>(); personList.add(new Person("Tom", 20, "Male")); personList.add(new Person("Jerry", 22, "Male")); personList.add(new Person("Lucy", 20, "Female")); personList.add(new Person("Lily", 22, "Female")); // 分组 Map<Integer, List<Person>> groupMap = personList.stream().collect(Collectors.groupingBy(Person::getAge)); // 导出数据 List<GroupExportVo> exportList = new ArrayList<>(); for (Map.Entry<Integer, List<Person>> entry : groupMap.entrySet()) { GroupExportVo exportVo = new GroupExportVo(); exportVo.setAge(entry.getKey()); exportVo.setPersonList(entry.getValue()); exportList.add(exportVo); } // 使用Easypoi导出数据 ExcelUtils.exportExcel(exportList, "分组导出数据", "Sheet1", GroupExportVo.class, "分组导出数据.xls"); } ``` 其中,GroupExportVo类定义如下: ```java public class GroupExportVo { @Excel(name = "年龄") private Integer age; @ExcelCollection(name = "人员列表") private List<Person> personList; // getter和setter方法省略 } ``` 运行上述代码后,即可将分组后的数据导出为Excel文件。具体实现过程中,我们使用了Java 8的Stream API中的groupingBy()方法进行分组,然后使用Easypoi库导出数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值