java stream操作案例

來源:互聯網
上載者:User

標籤:array   ppi   contains   stream   npos   osi   filter   hash   tst   

1、從List<Staff>篩選合格List<String>:

List<Staff> staffListtemp=Lists.newArrayList();List<String> staffIdList=staffListtemp.stream().filter(staff->deptIdSet.contains(staff.getDeptId())).map(staffId->staffId.getStaffId()).collect(Collectors.toList());

2、從List<PositionRealtime>轉為Map<String,PositionRealtime>:

List<PositionRealtime> prListMap<String,PositionRealtime> prMap=prList.stream().collect(Collectors.toMap(PositionRealtime::getStaffId, PositionRealtime->PositionRealtime));

3、從Set<String>轉為拼接後的String:

Set<String> inPostStaffIds = Sets.newHashSet();String inPostIds = inPostStaffIds.stream().reduce((a,b)->a+","+b).get();

4、從List<StaffGpsTimeDTO>通過StaffId作為分組條件分組為Map<String,List<StaffGpsTimeDTO>>對象:

List<StaffGpsTimeDTO> positionHistoryTimeList = positionHistoryManageDao.getPositionHistoryTimeList(filterPropertyMap2);for(StaffGpsTimeDTO staffGpsTimeDTO : positionHistoryTimeList){    List<Date> list = Lists.newArrayList();    if(gpsMap.get(staffGpsTimeDTO.getStaffId()) != null){        list = gpsMap.get(staffGpsTimeDTO.getStaffId());    }    list.add(staffGpsTimeDTO.getGpsTime());    gpsMap.put(staffGpsTimeDTO.getStaffId(), list);}Map<string,List<>> aaa=positionHistoryTimeList.stream().collect(Collectors.groupingBy(StaffGpsTimeDTO::getStaffId,Collectors.mapping(StaffGpsTimeDTO::getGpsTime, Collectors.toList())));

java stream操作案例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.