当前位置:网站首页>Stream stream creation_ Operation_ Collection_ case
Stream stream creation_ Operation_ Collection_ case
2022-06-22 09:13:00 【C_ x_ three hundred and thirty】
package com.Cx_330.run;
import org.junit.Test;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class CCC {
public static double allNums;
public static void main(String[] args) {
//Collection
List<String> list=new ArrayList<>();
Collections.addAll(list," Zhang San "," Li Si "," Zhang Si "," Axin "," Zhang Xiaosan "," Zhang Si "," Zhang Si "," Zhang San ");
list.stream();
//Map
Map<Integer,String> map=new HashMap<>();
Stream<Integer> keystream = map.keySet().stream();
Stream<String> valuestream = map.values().stream();
Stream<Map.Entry<Integer, String>> entrystream = map.entrySet().stream();
//Arrays
String[] str= {" Zhang Xiaosan "," Li Si "," Zhang ha "," Zhang Sanfeng "};
Stream<String> strstream = Arrays.stream(str);
Stream<String> str1 = Stream.of(str);
// middleware
System.out.println("\n--------- Zhang --------------------");
list.stream().filter(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.startsWith(" Zhang ");
}
}).forEach((s)-> System.out.print(s+" "));
System.out.println("\n--------- The surname Zhang --------------------");
list.stream().filter(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.startsWith(" Zhang ");
}
}).filter(new Predicate<String>() {
@Override
public boolean test(String s) {
return s.length()==2;
}
}).forEach((s)-> System.out.print(s+" "));
System.out.println("\n-------- The surname Zhang is two words and only the first one ---------------");
list.stream()
.filter((s)->s.startsWith(" Zhang "))
.filter((s)->s.length()==2)
.limit(1L)
.forEach((s)-> System.out.print(s+" "));
System.out.println("\n-------- Zhang and skip the first one ---------------");
list.stream()
.filter((s)->s.startsWith(" Zhang "))
.filter((s)->s.length()==2)
.skip(1L)
.forEach((s)-> System.out.print(s+" "));
System.out.println("\n-------- Zhang's name and two words and remove the repetition ---------------");
list.stream()
.filter((s)->s.startsWith(" Zhang "))
.filter((s)->s.length()==2)
.distinct()
.forEach((s)-> System.out.print(s+" "));
System.out.println("\n-------- Merge the two words Zhang and Li and remove the repetition ---------------");
Stream<String> s1 = list.stream()
.filter((s) -> s.startsWith(" Zhang "))
.filter((s) -> s.length() == 2)
.distinct();
Stream<String> s2 = list.stream().filter(s -> s.startsWith(" Li "));
Stream<String> sss = Stream.concat(s1, s2);
sss.forEach(s-> System.out.print(s+" "));
System.out.println("\n-------- Find the number of Li ---------------");
long len = list.stream().filter(s -> s.startsWith(" Li ")).count();
System.out.println(len);
System.out.println("***********************************");
ArrayList<Double> doubles = new ArrayList<>();
Collections.addAll(doubles,1.0,2.0,3.0,4.0,5.0,6.0,7.0);
// Remove the maximum minimum value Average
// It defines a allNums As a shared variable Receive sum
// averaging First Rank ascending Removing In ergodic summation
doubles.stream()
.sorted((d1,d2)->Double.compare(d1,d2))
.skip(1)
.limit(doubles.size()-2)
.forEach(d->allNums+=d);
System.out.println(" The average value is : "+allNums/(doubles.size()-2));
System.out.println("\n-------- Merge the two words surnamed Zhang and remove the repetition and return to one List aggregate ---------------");
List<String>stringList=list.stream()
.filter((s) -> s.startsWith(" Zhang "))
.filter((s) -> s.length() == 2)
.distinct()
.collect(Collectors.toList());
System.out.println(stringList);
}
}
边栏推荐
- 求余弦的大小
- Xshell远程服务器tensorboard/visdom的本地可视化方法【亲测一步有效】
- Two threads execute i++ 100 times respectively, and the possible values obtained
- . A use of file link library
- Express bird of Express query demonstration code (php+curl)
- Node cannot recognize the 'node' entry as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is correc
- Function summary (1)
- 字符串与内存操作函数详解与模拟实现
- Introduction to ten free and open source PHP online stores abroad
- PHP online common color comparison table
猜你喜欢

kali木马入侵win7系统

项目优化+上线(掌握了么?)

为啥要使用梯度下降法

User insight into the video industry in January 2022: active users began to pick up under the influence of holidays

【node】理论+实践让你拿下session、cookie

前馈和反向传播

【详解】神经网络矩阵的点乘与叉乘(pytorch版)
![[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats](/img/c9/c0ee95e816cac698f5397cc369d9ec.jpg)
[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats

Byte/byte?别搞晕了!

Didi's two-sided summary
随机推荐
一学就会的tensorflow断点续训(原理+代码详解)
VMware安装Kali
np. Arange and np Linspace nuances (data overflow problem)
前馈和反向传播
In the monorepo learning, execute NPM run build to report error[err\u require\esm] of ES module
无线路由攻击和WiFi密码破解实战[渗透技术]
OpenCV每日函数 直方图相关(3)
Solid from entry to practice (end)
threejs实现简单全景看房demo
traefik ingress实践
[Architect (Part 39)] connecting MySQL database developed by server
【node】快收下爬虫,我们不再为数据发愁
性能优化专题
炒股致富之curl抓股票信息
Introduction to ten free and open source PHP online stores abroad
File upload attack and protection
Solidity from introduction to practice (V)
DOM programming
Classification of SQL language
机器学习|nltk_Data下载错误|nltk的stopwords语料下载错误解决方法