lambda之List

List<Grid.NafpGridDS>转为List<List>
方法一:老旧方法

		List<Grid.NafpGridDS> dsList = bean.getDSList();
		List<List<Double>> ds = new ArrayList<>();
		for(Grid.NafpGridDS d : dsList){
			List<Double> numbers = new ArrayList<>();
			ProtocolStringList protocolStringList = d.getRowList();
			for(int i=0;i<protocolStringList.size();i++){
				numbers.add(Double.parseDouble(protocolStringList.get(i)));
			}
			ds.add(numbers);
		}

方法二:

		List<Grid.NafpGridDS> dsList = bean.getDSList();
		List<List<Double>> ds = new ArrayList<>();
		dsList.stream().forEach(d -> {
			ArrayList<Double> numbers = new ArrayList<>();
			d.getRowList().stream().map(p -> numbers.add(Double.parseDouble(p))).collect(Collectors.toList());
			ds.add(numbers);
		});

方法三:

		List<Grid.NafpGridDS> dsList = bean.getDSList();
		List<List<Double>> ds = new ArrayList<>();
		dsList.stream().forEach(d -> {
			ds.add(d.getRowList().stream().map(p -> Double.parseDouble(p)).collect(Collectors.toList()));
		});

方法四:

		List<Grid.NafpGridDS> dsList = bean.getDSList();
		List<List<Double>> ds = dsList.stream().map(grid -> grid.getRowList().stream().map(Double::parseDouble).collect(Collectors.toList())).collect(Collectors.toList());
		//List<List<Double>> ds = dsList.stream().map(grid -> grid.getRowList().stream().map(p -> Double.parseDouble(p)).collect(Collectors.toList())).collect(Collectors.toList());

双List循环查询输出固定对象
方法一:旧方法

		for(Grid.AvalibleResponse a : avalibleResponseList){
			List<Grid.AvalibleResponseRow> rows = a.getRowList();
			for(Grid.AvalibleResponseRow row : rows){
				String feature = row.getFeature();
				if(feature.toLowerCase().equals("d")){
					System.out.println("feature = " + feature);
					System.out.println("row.getLevelsList() = " + row.getLevelsList().stream().sorted().collect(Collectors.toList()));
					System.out.println("row.getValidtimesList() = " + row.getValidtimesList().stream().sorted(Comparator.comparing(Integer::parseInt)).collect(Collectors.toList()));
				}
			}
		}

方法二:

		List<Grid.AvalibleResponseRow> rows = avalibleResponseList.get(0).getRowList();
		Grid.AvalibleResponseRow rowOptional = rows.stream()
				.filter(row -> row.getFeature().toLowerCase().equals("d"))
				.findFirst()
				.get();
		System.out.println("feature = " + rowOptional.getFeature());
		System.out.println("Validtimes = " + rowOptional.getValidtimesList().stream().sorted(Comparator.comparing(Integer::parseInt)).collect(Collectors.toList()));
		System.out.println("LevelsList = " + rowOptional.getLevelsList().stream().sorted().collect(Collectors.toList()));

由于重复数据很多,filter过滤后,findFirst()只取第一条或者用.distinct()去重复也可以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值