List分组
Map<Integer, List<Sku>> mapList = list.stream().collect(Collectors.groupingBy(Sku::getProductSpecificationId));
List转Map
Map<Integer, Sku> appleMap = list.stream().collect(Collectors.toMap(Sku::getProductSpecificationId, item -> item));
List获取指定的字段集合
List<Integer> idList = list.stream().map(Sku::getId).collect(Collectors.toList());
List排序
Sku.stream().sorted(Comparator.comparing(Sku::getId).reversed()).collect(Collectors.toList());
List去重
List<String> numbers = list.stream().distinct().collect(Collectors.toList());
List过滤
List<Sku> collect = list.stream().filter(item -> Arrays.asList("aaa", "bbb").contains(item.getHaha())).collect(Collectors.toList());
List int 结果之和
Integer sum = list.stream().mapToInt(Integer::intValue).sum();
List转换逗号分隔的字符串
StringUtils.join(list, ",")
List类型转换
String[] aaa = "1-2-3".split("-");
List<Integer> bbb = Arrays.asList(aaa).stream().map(Integer::parseInt).collect(Collectors.toList());
LocalDate处理
月初:LocalDate.now().withDayOfMonth(1)
月末:LocalDate.now().with(TemporalAdjusters.lastDayOfMonth())
字符串转日期:LocalDate.parse("2024-05-01")
日期转字符串:DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formattedDate = date.format(formatter);
Date处理
字符串转日期:DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.parse(dateString)
日期转字符串:SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = sdf.format(date);