java数组或集合转换
字符串数组转int数组
String[] ids= {“1”, “2”, “3”};
int[] array = Arrays.asList(ids).stream().mapToInt(Integer::parseInt).toArray();
int[] array = Arrays.stream(ids).mapToInt(Integer::parseInt).toArray();
List转String数组
List list = new ArrayList();
list.add(“a1”);
list.add(“a2”);
String[] arr = list.toArray(new String[list.size()]);
对象获取ids集合
Set clazzId = list.stream().map(p -> p.getClazz().getId()).collect(Collectors.toSet());
String数组转List
String[] ids= {“1”, “2”, “3”};
List list = Arrays.asList(ids);
获取Set集合单一元素
set.stream().findFirst().get()
移除元素
list.removeIf(e -> materialIds.contains(e.getId()));
stream分组
Map<String, List> jshStockDetailMap = jshStockDetailList.stream().collect(Collectors.groupingBy(JshStockDetail::getId));
stream升序
ps:需要重新赋值否则不起作用
List materialList = materialList.stream().sorted(Comparator.comparing(MaterialTreeVO::getCreateTime)).collect(Collectors.toList());
stream 降序
ps:需要重新赋值否则不起作用
List materialList = materialList.stream().sorted(Comparator.comparing(MaterialTreeVO::getCreateTime).reversed()).collect(Collectors.toList());
stream 逗号分割成字符串
List list = new ArrayList<>();
list.add(“b”);
list.add(“c”);
list.stream().collect(Collectors.joining(“,”)).concat(“,”);
list转map (单字段)
Map<String, Users> collect = list.stream().collect(Collectors.toMap(Users::getUserId, Function.identity()));
list转map (多个字段)
Map<String, BigDecimal> collect = yarnMaterialInfos.stream().collect(Collectors.toMap(p -> p.getInfoGauzeBatch() + “-” + p.getInfoMaterialId(), ProduceYarnMaterialInfo::getMaterialPercent));