Jdk8 lambda 表达式例子

public static void test(){
	List<DwMmDefVO> vos = new ArrayList<DwMmDefVO>();
	DwMmDefVO temp = new DwMmDefVO();
	temp.setDsName("name1");
	temp.setDefType("Type1");
	temp.setPk("PK1");
	temp.setPkDs("DS1");
	temp.setPkDef("def1");
	vos.add(temp);
		
	//遍历
	vos.forEach(vo -> {  
            System.out.println(vo.getDsName()+ "---" + vo.getPath());  
     });
		
	//获取(key value) 第三个参数能解决重复key的问题
    vos.stream().collect(Collectors.toMap(DwMmDefVO::getPk,DwMmDefVO::getDsName,
        (oldValue, newValue) -> oldValue));

    //获取(key Object)
	Map studentMap = vos.stream().collect(Collectors.toMap(DwMmDefVO:: getPkDef, (k) -> k)); 
		
	//获取某一列数据
	List<String> strs = vos.stream().map(DwMmDefVO::getDsName)
			.collect(Collectors.toList());
		
	//获取固定字符数据
	vos = vos.stream().filter(x -> x.getDsName().equals("0"))
		.distinct().collect(Collectors.toList());
		
	//排序
	vos = vos.stream().sorted((s1,s2) -> s1.getPkDs().compareTo(s2.getPkDs()))
		.collect(Collectors.toList());
				
	//分组
	Map<String,List<DwMmDefVO>> group = vos.stream()
		.collect(Collectors.groupingBy(DwMmDefVO::getDefType));
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值