当前位置:网站首页>collect.stream().collect()方法的使用
collect.stream().collect()方法的使用
2022-06-11 19:03:00 【后觉2022】
Stream的用法:
1:简单无存储,属于数据源的一个单向视图.
2.对于stream的任何修改,都不会修改到原来的list,这就是我上面所说的单向.比如你对strram进行排序或者删除操作,原来的list不会作任何改变,会产生一个新的你操作之后的stream视图.
3.惰式执行 对 stream的操作并不回立即执行,如果用户真正需要的时候才会执行(有点像system.gc()方法)
4.消费即消失 生成的stream视图一旦遍历就会消失,如果需要则要重新生成
stuMap=stuList.stream().collect(Collectors.toMap(Student::getSex,student->student, (key1, key2) -> key2));
这行代码Student::getSex,student->student代表利用student.getSex作为key,student作为value,
同理如果想用student.name作为value可以这样写
stuMap=stuList.stream().collect(Collectors.toMap(Student::getSex,Student::getName, (key1, key2) -> key2));
(key1, key2) -> key2)这一行代码指的是合并冲突的解决办法,比如最开始两男一女时,
第一个男被合并到第二个男上面,同理如果想以key的第一个值为准,可以写成(key1, key2) -> key1
边栏推荐
- Introduction to basic use and pit closure of BigDecimal
- 【信号去噪】基于非线性滤波器实现语音自适应去噪附matlab代码
- Visual slam lecture notes-10-2
- The 2023 MBA (Part-time) of Beijing University of Posts and telecommunications has been launched
- [Multisim Simulation] using operational amplifier to generate sawtooth wave
- 【视频去噪】基于SALT实现视频去噪附Matlab代码
- Pymysql uses cursor operation database method to encapsulate!!!
- Kubernetes binary installation (v1.20.15) (VIII) deploying network plug-ins
- Tips for using apipost
- Niuke brush questions part7
猜你喜欢
![leetcode:剑指 Offer 59 - II. 队列的最大值[deque + sortedlist]](/img/6b/f2e04cd1f3aaa9fe057c292301894a.png)
leetcode:剑指 Offer 59 - II. 队列的最大值[deque + sortedlist]

On the sequence traversal of binary tree

On the sequence traversal of binary tree Ⅱ

Quanzhi technology T3 development board (4-core arm cortex-a7) - video development case
![[signal denoising] signal denoising based on FFT and fir with matlab code](/img/4c/782afe2652a674d64fccd8d28304ed.png)
[signal denoising] signal denoising based on FFT and fir with matlab code

Teach you how to learn the first set and follow set!!!! Hematemesis collection!! Nanny level explanation!!!

WWDC22 开发者需要关注的重点内容
Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics

The 2023 MBA (Part-time) of Beijing University of Posts and telecommunications has been launched

ASEMI的MOS管25N120在不同应用场景的表现
随机推荐
Kubernetes binary installation (v1.20.15) (VIII) deploying network plug-ins
Uni app Muke hot search project (I) production of tabbar
Niu Ke swipes the question -- converting a string to an integer
Construct enemy tanks
手把手教你学会FIRST集和FOLLOW集!!!!吐血收藏!!保姆级讲解!!!
Make a static tank
全国院校MBA、EMBA、MPA、MEM、提前面试(预面试)时间批次已出(持续更新中)-文都管联院
Niuke brush questions part8
Niuke brush questions part6
【视频去噪】基于SALT实现视频去噪附Matlab代码
Uploading and downloading of necessary files in development
An adaptive chat site - anonymous online chat room PHP source code
【题解】Codeforces Round #798 (Div. 2)
Visual slam lecture notes-10-2
Mysql从0到1的完全深入学习--阶段二---基础篇
Quanzhi T3 development board (4-core arm cortex-a7) - detailed explanation of logo display during system startup
Experience of remote office communication under epidemic situation | community essay solicitation
一款自适应的聊天网站-匿名在线聊天室PHP源码
Financial bank_ Introduction to collection system
Visual slam lecture notes-10-1