最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Stream流排序數(shù)組和List?詳解

 更新時間:2022年09月21日 10:27:42   作者:李長淵哦  
這篇文章主要介紹了Stream流排序數(shù)組和List?詳解,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,感興趣的小伙伴可以參考一下

一、對象單字段排序

        List<People> peopleList = Lists.newArrayList();
        peopleList.add(new People(1, "小王", 5));
        peopleList.add(new People(1, "小李", 4));
        peopleList.add(new People(2, "小張", 3));
        peopleList.add(new People(2, "小皇", 2));
        peopleList.add(new People(2, "小劉", 1));

        //單字段排序
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //這里是根據(jù)userId 進行排序——降序排序  reversed()
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getJgId).reversed()).collect(Collectors.toList());
        log.info(peopleList.toString());

二、多字段排序

        List<People> peopleList = Lists.newArrayList();
        peopleList.add(new People(1, "小王", 5));
        peopleList.add(new People(1, "小李", 4));
        peopleList.add(new People(2, "小張", 3));
        peopleList.add(new People(2, "小皇", 2));
        peopleList.add(new People(2, "小劉", 1));
        //這里是根據(jù)Id及jgId進行聯(lián)合升序排序
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId).thenComparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //下面兩個結(jié)果都是以Id降序jgId升序排序的結(jié)果,但是查詢方式不同
        //先以id升序,升序結(jié)果進行id降序,再進行jgId升序
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId).reversed().thenComparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //先以id降序,再進行jgId升序 **推薦使用該種方式**
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId,Comparator.reverseOrder()).thenComparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //先以id升序,再進行jgId降序
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId).thenComparing(People::getJgId,Comparator.reverseOrder())).collect(Collectors.toList());
        log.info(peopleList.toString());

三、數(shù)組排序以及List<Integer>排序

先把數(shù)組轉(zhuǎn)換成List對象再進行排序

到此這篇關(guān)于Stream流排序數(shù)組和List 詳解的文章就介紹到這了,更多相關(guān)Stream List 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

静安区| 汉川市| 沙湾县| 冷水江市| 福鼎市| 同德县| 灵璧县| 察隅县| 兴和县| 安仁县| 眉山市| 鄂托克旗| 青川县| 德昌县| 林甸县| 鄂伦春自治旗| 宁南县| 金堂县| 施秉县| 潮州市| 海晏县| 海口市| 固始县| 郸城县| 长岭县| 屏东县| 天气| 鲁甸县| 读书| 临夏县| 神木县| 井研县| 吴川市| 灵璧县| 丹凤县| 尚志市| 海口市| 安塞县| 吉水县| 漯河市| 德格县|