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()去重复也可以