美文网首页
java常见语法

java常见语法

作者: Jinx菜鸟之路 | 来源:发表于2022-03-28 15:37 被阅读0次

    一、去除list对象中的某一个值并封装成list

    Set targetIds = tradeTerminalTargets.stream().map(TradeTerminalTarget::getId).collect(Collectors.toSet());

    二、list<Object> -> map<xx, Object> 

    Map collect = tradeProducts.stream()

    .collect(Collectors.toMap(TradeProduct::getMaterialNo, Function.identity()));

    多个字段组成key

    Map tradeProductMap = tradeProducts.stream()

    .collect(Collectors.toMap(s -> {

    return s.getMaterialNo()+s.getSalesModel();

    }, Function.identity()));

    list排序

    newDeptTreeNodeList.stream().sorted(Comparator.comparing(DeptTreeNode::getSortNo)).collect(Collectors.toList());

    list<T> 转 Map<key, List<T>>

    Map<String, List<String>> ruleNosVersionMap = anaRuleExcelBases.stream().collect(Collectors.groupingBy(AnaRuleExcelBase::getRuleNo, Collectors.mapping(AnaRuleExcelBase::getRuleVersion, Collectors.toList())));

    Map<String, List<String>> map = list.stream().collect(Collectors.toMap(Person::getId,

        p ->  {

        List<String> getNameList = new ArrayList<>();

        getNameList.add(p.getName());

        return getNameList;

        },

            (List<String> value1, List<String> value2) -> {

            value1.addAll(value2);

            return value1;

            }

        ));

    过滤list数据

    List<TimeData> end = haveData.stream().filter(endData ->

            endData.getEndData().compareTo(time) > 0).collect(toList());

    二、Optional.ofNullable(request.getChiidren()).orElse(clientEnum.Tineco.getcode())

    //        List  list = Lists.newArrayList();

    //        String join = Joiner.on(BasicConstants.COMMA).join(list);

    //        List<String> strings = Splitter.on(",").splitToList(join);

    三、判断对象是否为空

    Objects.nonNull(syncLog)

    Objects.nonNull(syncLog)

    Objects.equals

    四、集合拼接转String

    Joiner.on("&").join(keys)

    xx

    相关文章

      网友评论

          本文标题:java常见语法

          本文链接:https://www.haomeiwen.com/subject/dcavjrtx.html