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

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

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

一、對(duì)象單字段排序

        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 進(jìn)行排序——降序排序  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進(jìn)行聯(lián)合升序排序
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId).thenComparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //下面兩個(gè)結(jié)果都是以Id降序jgId升序排序的結(jié)果,但是查詢方式不同
        //先以id升序,升序結(jié)果進(jìn)行id降序,再進(jìn)行jgId升序
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId).reversed().thenComparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //先以id降序,再進(jìn)行jgId升序 **推薦使用該種方式**
        peopleList =  peopleList.stream().sorted(Comparator.comparing(People::getId,Comparator.reverseOrder()).thenComparing(People::getJgId)).collect(Collectors.toList());
        log.info(peopleList.toString());
        //先以id升序,再進(jìn)行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對(duì)象再進(jìn)行排序

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

相關(guān)文章

最新評(píng)論

阿巴嘎旗| 汉阴县| 南部县| 南川市| 平邑县| 新闻| 济阳县| 遂昌县| 淅川县| 诸城市| 杂多县| 大竹县| 页游| 昌平区| 长春市| 察哈| 三河市| 体育| 垫江县| 当阳市| 新巴尔虎左旗| 呈贡县| 黄骅市| 年辖:市辖区| 无为县| 张家口市| 义马市| 沙雅县| 江口县| 西乌| 万载县| 虹口区| 雅安市| 颍上县| 益阳市| 从化市| 钟祥市| 南城县| 武隆县| 高陵县| 深州市|