jdk1 8日常使用示例

2021-10-01 23:35:27 字數 1709 閱讀 2165

jdk1.8日常使用示例

//1、list轉map

listlistvo = lists.newarraylist();

//todo賦值

mapresultmap = listvo.stream().collect(collectors.tomap(regionvo::getid, function.identity()));

//2、list轉map,分組

listlistpath=lists.newarraylist();

//todo賦值

listabstractobjectinfos =lists.newarraylist();

//todo賦值

mapobjectinfomap = abstractobjectinfos.stream()

.collect(streamcollectors.tohashmap(abstractobjectinfo::getabstractobjectukid, function.identity()));

//3、list轉set

liststorageviews = lists.newarraylist();

//todo賦值

setbusinessids = storageviews.stream().map(storageview::getgoodsownerukid).collect(collectors.toset());

4、list 求和(整數)

listswstoragedetails = lists.newarraylist();

//todo賦值

//商品總數

long goodstotal = swstoragedetails.stream().maptolong(swstoragedetail::getgoodsamount).sum();

//5、list 求和(整數)bigdecimal 型別資料求和,使用reduce

參考bigdecimal add = list.stream().map(user::getheight).reduce(bigdecimal.zero, bigdecimal::add);

//6. 過濾出所有引數型別為入參的引數

listinparamlist = gwserviceparamdtolist.stream()

.filter(a -> a.getparaminoutype() == in_param_type).collect(collectors.tolist());

賦值map> contractcontainermap = new hashmap<>(16);

for (.....)

//8.取最值

//取最長備註

string remark = setransferorders.stream().max((o1, o2)-> ).get().getremark();

// 9.拋異常

long relationukid = optional.ofnullable(imsubitemservice.getbysubitemukid(relationukid)).map(imsubitem::getitemukid).orelsethrow(not_found_group);

// 10.過濾

if (relations.stream().anymatch((a) -> a.getstepflow() < 5))

jdk1 8的部分使用方式

mapscheduleplanmap new hashmap list list new arraylist scheduleplanmap.keyset 獲取所有的key的集合 list list1 scheduleplanmap values stream collect collectors....

05日常高階使用

04 軟體安裝 序號命令 作用01 find 路徑 name py 查詢指定路徑下副檔名是.py的檔案,包括子目錄 序號 命令作用 01ln s 被鏈結的原始檔 鏈結檔案 建立檔案的軟鏈結,類似於windows下的快捷方式 打包檔案 tar cvf py.tar 將該目錄下所有檔案打包成py.tar...

JDK1 8安裝 配置 注意事項及示例

安裝示例 新建j a home 變數值為安裝路徑 path配置 安裝成功 j a 8 又稱為 jdk 1.8 是 j a 語言開發的乙個主要版本。oracle 公司於 2014 年 3 月 18 日發布 j a 8 它支援函式式程式設計,新的 j ascript 引擎,新的日期 api,新的stre...