目錄
1、初始化bean
2、分組在分組
3、分組去重統計
4、分組統計
public class user
public user(int age)
public user()
public int getheigh()
public void setheigh(int heigh)
public int getage()
public void setage(int age)
@override
public string tostring() ';
}}
/**
* 分組之後再分組
* * @author hubozhi
* @date 2020/8/30 16:07
**/public class streamstudy
//檢視分組情況
map> collect = userlist.stream().collect(collectors.groupingby(user::getage));
collect.foreach((k, v) -> );
}public static void main(string args) );
});});
}}
/**
* 分組去重統計:先分組,在對每組中的資料進行去重,在對去重後的結果進行統計
* * @author hubozhi
* @date 2020/8/30 16:09
**/public class streamstudy2
//檢視分組情況
map> collect = userlist.stream().collect(collectors.groupingby(user::getage));
collect.foreach((k, v) -> );
}public static void main(string args) );
});//分組去重並轉換為list
map> groupanddistinctandtolist = userlist.stream().collect(collectors.groupingby(user::getage, collectors.collectingandthen(
collectors.tocollection(() -> new treeset<>(comparator.comparing(user::getheigh))), arraylist::new)));
groupanddistinctandtolist.foreach((k,v)->);
});//分組去重統計
mapgroupanddistinctandcount =
userlist.stream().collect(
collectors.groupingby(
user::getage,
//去重並統計
collectors.collectingandthen(
collectors.tocollection(
() -> new treeset<>(comparator.comparing(user::getheigh))
),set::size))
);groupanddistinctandcount.foreach((k, v) -> );
}}
/**
* 分組統計:先分組,在統計每組中元素的個數
* * @author hubozhi
* @date 2020/8/30 16:18
**/public class streamstudy3
//檢視分組情況
map> collect = userlist.stream().collect(collectors.groupingby(user::getage));
collect.foreach((k, v) -> );
}public static void main(string args) );
}}
Stream基礎篇 Stream入門應用
分割槽是有狀態處理中的乙個關鍵概念,無論是效能還是一致性的原因,分割槽都是至關重要的,當生產者將訊息資料傳送給多個消費者例項時,保證擁有共同特徵的訊息資料始終是由同乙個消費者例項接收和處理。例如,在時間窗平均計算示例中,來自任何給定感測器的所有測量值都由相同應用程式例項處理是很重要的。注 要設定分割...
Stream初步應用
stream 流 是乙個來自資料來源的元素佇列並支援聚合操作,資料 可以從inputstream,陣列,集合中獲取 聚合操作可以類似sql語句一樣的操作,比如filter,map,reduce,find,match,sorted等。public class streamrefer 流的方法測試 te...
Stream應用注意點
1.stream 的類層次 2.stream 的狀態 iostate io 格式化flag fmtflags 檔案開啟模式 openmode 檔案定位標記 seekdir 3.stream 中failbit 和 badbit 的差別。failbit 用於讀取時格式不符的情況。注意,在格式不符時,st...