zoukankan      html  css  js  c++  java
  • 使用Lambda .map函数将入参List转换至其它List

    import com.alibaba.fastjson.JSON;
    import com.example.demo.Demo.dto.Student;
    import com.example.demo.pojo.StudentPlus;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Date;
    import java.util.List;
    import java.util.stream.Collectors;
    
    public class map {
        public static void main(String[] args) {
            Student stu1 = new Student();
            stu1.setId(1);
            stu1.setName("张三");
            stu1.setDate(String.valueOf(new Date()));
    
            Student stu2 = new Student();
            stu2.setId(2);
            stu2.setName("李四");
            stu2.setDate(String.valueOf(new Date()));
    
            //过滤学生
            List<StudentPlus> stuPlusList;
    
    
            //装载学生类
            List<Student> stuList = new ArrayList<>();
            Collections.addAll(stuList, stu1, stu2);
    
            //执行逻辑转换
            stuPlusList = stuList.stream().map(item -> {
                StudentPlus stuPlus = new StudentPlus();
                stuPlus.setId(item.getId());
                stuPlus.setName(item.getName());
                stuPlus.setDate(new Date(item.getDate()));
                return stuPlus;
            }).collect(Collectors.toList());
    
            //输出
            System.out.println(JSON.toJSON(stuPlusList));
        }
    }
    
  • 相关阅读:
    python3调用js的库之execjs
    字体替换 re.sub
    asyncio和aiohttp
    微信公众号数据抓取
    celery
    Airtest 的连接安卓模拟器
    Scrapy同时启动多个爬虫
    随机IP代理插件Scrapy-Proxies
    Charles和mitmproxy代理设置
    win下删除EFI分区
  • 原文地址:https://www.cnblogs.com/Twittery/p/15003243.html
Copyright © 2011-2022 走看看