這篇文章主要介紹“java8 stream的分組功能實(shí)例用法”,在日常操作中,相信很多人在java8 stream的分組功能實(shí)例用法問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”java8 stream的分組功能實(shí)例用法”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

網(wǎng)站建設(shè)公司,為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì)及定制網(wǎng)站建設(shè)服務(wù),專注于成都企業(yè)網(wǎng)站建設(shè),高端網(wǎng)頁(yè)制作,對(duì)建筑動(dòng)畫等多個(gè)行業(yè)擁有豐富的網(wǎng)站建設(shè)經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。專業(yè)網(wǎng)站設(shè)計(jì),網(wǎng)站優(yōu)化推廣哪家好,專業(yè)seo優(yōu)化優(yōu)化,H5建站,響應(yīng)式網(wǎng)站。
public static void testStreamGroup(){ List<Student> stuList = new ArrayList<Student>(); Student stu1 = new Student("10001", "孫權(quán)", "1000101", 16, '男'); Student stu2 = new Student("10001", "曹操", "1000102", 16, '男'); Student stu3 = new Student("10002", "劉備", "1000201", 16, '男'); Student stu4 = new Student("10002", "大喬", "1000202", 16, '女'); Student stu5 = new Student("10002", "小喬", "1000203", 16, '女'); Student stu6 = new Student("10003", "諸葛亮", "1000301", 16, '男'); stuList.add(stu1); stuList.add(stu2); stuList.add(stu3); stuList.add(stu4); stuList.add(stu5); stuList.add(stu6); Map<String, List<Student>> collect = stuList.stream().collect(Collectors.groupingBy(Student::getClassId)); for(Map.Entry<String, List<Student>> stuMap:collect.entrySet()){ String classId = stuMap.getKey(); List<Student> studentList = stuMap.getValue(); System.out.println("classId:"+classId+",studentList:"+studentList.toString()); }}classId:10002,studentList:[Student [classId=10002, name=劉備, studentId=1000201, age=16, sex=男], Student [classId=10002, name=大喬, studentId=1000202, age=16, sex=女], Student [classId=10002, name=小喬, studentId=1000203, age=16, sex=女]]classId:10001,studentList:[Student [classId=10001, name=孫權(quán), studentId=1000101, age=16, sex=男], Student [classId=10001, name=曹操, studentId=1000102, age=16, sex=男]]classId:10003,studentList:[Student [classId=10003, name=諸葛亮, studentId=1000301, age=16, sex=男]]
從上面的數(shù)據(jù)可以看出來(lái),stuList被分成了三個(gè)組,每個(gè)組的key都是classId,而每個(gè)classId都對(duì)應(yīng)一個(gè)學(xué)生列表,這樣就很輕松地實(shí)現(xiàn)了數(shù)據(jù)的分離;此時(shí),無(wú)論需要對(duì)數(shù)據(jù)進(jìn)行怎樣的處理都會(huì)很容易。
到此,關(guān)于“java8 stream的分組功能實(shí)例用法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
網(wǎng)站欄目:java8stream的分組功能實(shí)例用法
URL標(biāo)題:http://www.chinadenli.net/article42/pgcehc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、虛擬主機(jī)、域名注冊(cè)、網(wǎng)站排名、自適應(yīng)網(wǎng)站、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)