将对象的部分属性重组为集合
List<String> msgIds = messageExts.stream().map(e ->e.getMsgId()).collect(Collectors.toList());
将List集合转为Map
Map<String,MessageExt> messageExtMap = messageExts.stream().collect(Collectors.toMap(MessageExt::getMsgId, Function.identity()));
过滤数据组成新的集合
List<String> msgIds = msgIds.stream().filter(msgId -> !Objects.equals(msgId,"xxx")).collect(Collectors.toList());
集合转换类型
List<Long> msgIdLongs = msgIds.stream().map(Long::parseLong).collect(Collectors.toList());
正序排序
messageExts.sort(Comparator.comparing(MessageExt::getBornTimestamp));
倒序排序
messageExts.sort(Comparator.comparing(MessageExt::getBornTimestamp).reversed());
多条件正序
messageExts.sort(Comparator.comparing(MessageExt::getBornTimestamp).thenComparing(MessageExt::getBornHostString));
多条件倒序 messageExts.sort(Comparator.comparing(MessageExt::getBornTimestamp).reversed().thenComparing(MessageExt::getBornHostString));
分组
Map<Long, List<MessageExt>> demoOder = messageExts.stream().collect(Collectors.groupingBy(MessageExt::getBornTimestamp));