当前位置:网站首页>Stream stream calculation
Stream stream calculation
2022-06-22 06:18:00 【Kuxiaoya】
What is? Stream Flow computation
big data : Storage + Calculation
aggregate 、Mysql The essence is to store things ;
All calculations should be left to the flow !
Practice a problem :
- Subject requirements : Finish the problem in one minute , It can only be implemented in one line of code !
- Now by 6 Users ! Screening :
- 1、ID It must be an even number
- 2、 Age must be greater than 22 year
- 3、 Change user name to uppercase
- 4、 User names are sorted upside down
- 5、 Output only one user !
package stream;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
/** * Subject requirements : Finish the problem in one minute , It can only be implemented in one line of code ! * Now by 5 Users ! Screening : * 1、ID It must be an even number * 2、 Age must be greater than 23 year * 3、 Change user name to uppercase * 4、 User names are sorted upside down * 5、 Output only one user ! */
public class Test {
public static void main(String[] args) {
User u1 = new User(1, "a", 21);
User u2 = new User(2, "b", 22);
User u3 = new User(3, "c", 23);
User u4 = new User(4, "d", 24);
User u5 = new User(5, "e", 25);
User u6 = new User(6, "f", 26);
// A collection is storage
List<User> list = Arrays.asList(u1, u2, u3, u4, u5,u6);
// The calculation is given to Stream flow
list.stream()
.filter((u)->{
return u.getId()%2==0;})
.filter((u)->{
return u.getAge()>22;})
.map((u)->{
return u.getName().toUpperCase();})
.sorted((uu1,uu2)->{
return uu2.compareTo(uu1);})
.limit(1)
//.forEach(System.out::println);
.forEach((n)->{
System.out.println(n);
});
// Three equivalent operations
/* for (Object n : list) { System.out.println(n); } list.forEach(n -> System.out.println(n)); list.forEach(System.out::println);*/
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class User {
private int id;
private String name;
private int age;
}
边栏推荐
猜你喜欢

SQL 注入漏洞(十)二次注入

reduce_ Reduction in sum()_ indices

单细胞论文记录(part11)--ClusterMap for multi-scale clustering analysis of spatial gene expression

Subqueries in sqlserver

什么是JUC

性能对比分析
![[technical notes]](/img/5c/3a1fa6326f0bf16da8032526173343.png)
[technical notes]

W800 chip platform enters openharmony backbone

Single cell thesis record (Part12) -- unsupervised spatial embedded deep representation of spatial transcriptomics

Pyg tutorial (7): dissecting neighborhood aggregation
随机推荐
Bathymetry along Jamaica coast based on Satellite Sounding
单细胞论文记录(part13)--SpaGCN: Integrating gene expression, spatial location and histology to ...
Usage of trim, ltrim and rtrim functions of Oracle
Common auxiliary classes - (key)
单细胞论文记录(part9)--Spatial charting of single-cell transcriptomes in tissues
Flink核心功能和原理
Producer and consumer issues
什么是JUC
Subqueries in sqlserver
Entry level test kotlin implements popwindow pop-up code
线程池的三大方法
Single cell thesis record (part13) -- spagcn: integrating gene expression, spatial location and history to
【NAND文件系统】UBI介绍
[technical notes]
Detailed interpretation of tab[i = (n - 1) & hash]
Single cell literature learning (Part2) -- stplus: a reference based method for the exact enhancement of St
PyG教程(7):剖析邻域聚合
leetcode每周3道(八)图之最短路
集合类并发不安全问题
SQL 注入漏洞(十四)xff 注入攻击