java常见语法

2022-03-28  本文已影响0人  Jinx菜鸟之路

一、去除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

上一篇下一篇

猜你喜欢

热点阅读