现在项目中使用 Java 8 新特性的例子比比皆是,如果还不玩不明白,虽然代码看起来简洁,但是你未必知道什么意思。
1、foreach 的使用
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nf636ij30yf0u0jyr.jpg)
2、Stream 的使用
① Stream filter 方法:对集合元素进行过滤
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nfs5q3j30vp0u00wy.jpg)
person类
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9ngtbnwj313c0u0k1e.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nhlkm3j30v80fa41b.jpg)
② Stream map:数据映射转换
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nitaqxj30u20f8wh1.jpg)
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9njyqhfj31f10u0tg3.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nkfeqkj30nq0d6my5.jpg)
③ Stream flatMap:多维度转换数据,数据结构层级降维处理
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nlbfnbj30qi0e8dil.jpg)
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nmg0fcj31gp0u0qan.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nn9vvuj310r0u0myo.jpg)
④ Stream sort
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9no9p4mj30ua0u07im.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9noxezhj30y70u0tec.jpg)
⑤ Stream count、min 及 max 方法
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9npuantj311m0u0dru.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nqbbh0j30ya0fmq4k.jpg)
⑥ Stream skip(跳行方法) 和 limit(限行方法)
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nr4qwrj317c0u0ahj.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nrn4puj30ok0y0jsj.jpg)
⑦ Stream collect 方法:集合转换和数据流转换
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nskycaj31aw0u0dpf.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nt8yrkj30xt0u0jt2.jpg)
⑧ Stream concat 方法:通常用于拼接转换流
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9ntwhmpj31fg0u0n36.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nub3qhj310g0a4tae.jpg)
⑨ Stream reduce 聚合计算方法:通常与 map 搭配使用
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nv3vbtj31aw0u0475.jpg)
输出结果:
![用到停不下来,Java 8 新特性:foreach 和 stream](https://image.baidu.com/search/down?thumburl=https://baidu.com&url=https://tva1.sinaimg.cn/large/0080xEK2gy1ghw9nvj1j5j30mg0a8q3j.jpg)
最新评论
mat插件可以检测内存数据
标识接口?
序列化serializabel就是一个标识
就差一个MAC了
mark
除了预置sql查询字段,其他我竟然都没用过
可以,这个问题遇到过
mybatis多个参数: 1. 注解(最常用) 2. 转化为对象或MAP 3. 按顺序(这个最蠢,写的代码看得费劲) 单个参数需要注意得: 1.基本数据类型随便写 2.数组用array,l