• 请不要在回答技术问题时复制粘贴 AI 生成的内容
rqxiao
V2EX  ›  程序员

stream 有什么办法对分组后的每组元素内部进行排序吗

  •  
  •   rqxiao · Sep 23, 2019 · 4784 views
    This topic created in 2449 days ago, the information mentioned may be changed or developed.

    Map<String, List<introductionvideopagedto>> map = videoPageDtoList.stream().collect(Collectors.groupingBy(dto -> dto.getDataId()));</introductionvideopagedto>

    "3": [ { "id": "96ab01d10d66bb0fe41d3fc65b7eeca4", "title": "视频标题", "videoUrl": "11111111111", "dataId": "3", "sort": 2, "createTime": 1564041929000 }, { "id": "ef510c786580637e831ea532e925a312", "title": "课程标题课程标题", "videoUrl": "222222222222", "dataId": "3", "sort": 3, "createTime": 1568791200000 }, { "id": "efa01867ea0d6cf4cccc0020203c6928", "title": "课程标题", "videoUrl": "333333333333333333333333333333333333333", "dataId": "3", "sort": 1, "createTime": 1568790906000 } ]

    groupingBy 之后的这个 map 中 key stream 好像是默认已经排序了? 接着还想在组内对 sort 进行排序

    2 replies    2019-09-23 19:39:26 +08:00
    ayonel
        1
    ayonel  
       Sep 23, 2019
    必须一步到位么?
    https://stackoverflow.com/questions/29610465/sort-the-values-in-a-map-of-type-mapstring-liststring 这个两步可解决
    第二步:map.values().stream().forEach(l->l.sort(Compartor)) 大概这样
    Tsukihime
        2
    Tsukihime  
       Sep 23, 2019
    list.stream()
    .sorted(Comparator.comparing(IntroductionVideoPageDTO::getSort))
    .collect(Collectors.groupingBy(IntroductionVideoPageDTO::getDataId));
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2679 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 10:24 · PVG 18:24 · LAX 03:24 · JFK 06:24
    ♥ Do have faith in what you're doing.