当前位置: 首页 > news >正文

黄石商城网站建设产品软文范例

黄石商城网站建设,产品软文范例,wordpress时区问题,网址简化在线生成Stream流 定义 Steam流&#xff0c;用于操作集合或者数组中的数据&#xff0c;大量结合了Lamda表达式的语法风格&#xff0c;代码简洁。 重点&#xff1a; 流只能收集一次 ​ 获取Stream流 Stream流要与数据源建立连接。 1.list ​ 直接调用steam()即可 // list List<Stri…

Stream流

定义

Steam流,用于操作集合或者数组中的数据,大量结合了Lamda表达式的语法风格,代码简洁。

重点: 流只能收集一次

在这里插入图片描述


获取Stream流

Stream流要与数据源建立连接。

1.list

​ 直接调用steam()即可

// list
List<String> names = new ArrayList<>();
Collections.addAll(names, "品贵","红旗", "周芷若","张三丰");
Stream<String> stream = names.stream();
stream.filter(s -> s.contains("品")).forEach(s -> System.out.println(s));

2.set

​ 直接调用stream()即可

//set
Set<String> set = new HashSet<>();
Collections.addAll(set, "品贵","红旗", "三个人", "周芷若","张三丰","张三丰");
Stream<String> stream1 = set.stream();
stream1.filter(s -> s.contains("三")).forEach(s -> System.out.println(s));

3.map

​ 需要先将map转换为entrySet(),再通过entryset()进行获取stream()

//mapMap<String, Double> map = new HashMap<>(){{put("古力娜扎", 172.3);put("迪丽热巴", 175.3);put("古力娜扎", 171.4);put("稀里哗啦", 189.3);put("巴啦啦小魔仙", 160.1);}};
//        map.stream()Set<Map.Entry<String, Double>> entries = map.entrySet();Stream<Map.Entry<String, Double>> kvs = entries.stream();kvs.filter(e -> e.getKey().contains("巴")).forEach(System.out::println);
// 简便写法
map.entrySet().stream().filter(e -> e.getKey().contains("巴")).forEach(System.out::println);

4.数组

​ 使用Arrays.stream()

​ 使用Stream.of()

//数组
String[] names2 = {"张翠山", "东方不败", "大唐不夜城", "回民街"};
Stream<String> s1 = Arrays.stream(names2);
Stream<String> s2 = Stream.of(names2);

在这里插入图片描述


Steam流的常见中间方法

中间方法指的是调用完成后会返回新的Stream流,可以继续使用,支持链式编程。

在这里插入图片描述

package stream;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;public class Test2 {public static void main(String[] args) {List<Double> scores = new ArrayList<>();// 找出大于60分并升序排序后输出Collections.addAll(scores, 88.5, 100.0, 60.6, 99.0, 9.5, 99.6, 25.9);scores.stream().filter(s -> s >= 60).sorted().forEach(System.out::println);System.out.println("-------------------------------------------");List<Student> students = new ArrayList<>();Student s1 = new Student("蜘蛛精", 26, 172.5);Student s2 = new Student("蜘蛛精", 26, 174.5);Student s3 = new Student("紫霞", 216, 122.5);Student s4 = new Student("白晶晶", 25, 175.5);Student s5 = new Student("牛魔王", 13, 166.5);Collections.addAll(students, s1, s2, s3, s4, s5);// 找出年龄大于等于23 年龄小于等于30 并且按照年龄输出students.stream().filter(s -> s.getAge() >= 23 && s.getAge() <= 30).sorted((o1, o2) -> o2.getAge() - o1.getAge()).forEach(System.out::println);System.out.println("-------------------------------------------");// 取出身高前3名的学生 并输出students.stream().sorted((o1, o2) -> Double.compare(o2.getHeight(), o1.getHeight())).limit(3).forEach(System.out::println);System.out.println("-------------------------------------------");// 取出身高倒数2名学生,并输出students.stream().sorted((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight())).limit(2).forEach(System.out::println);System.out.println("-------------------------------------------");// 找出身高超过168的学生叫什么名字,要求去除重复的名字,再输出students.stream().filter(s -> s.getHeight() > 168).map(Student::getName).distinct().forEach(System.out::println);System.out.println("-------------------------------------------");// 找出身高超过168的学生叫什么名字,要求去除重复的内容,再输出// 首先需要重写equals和hashCode函数 让内容相同的对象设置为一样的students.stream().filter(s -> s.getHeight() > 168).distinct().forEach(System.out::println);System.out.println("-------------------------------------------");Stream<String> st1 = Stream.of("张三", "李四");Stream<String> st2 = Stream.of("张三2", "李四2", "王五");Stream.concat(st1, st2).forEach(System.out::println);}
}

Stream流常见的终结方法

在这里插入图片描述

在这里插入图片描述

package stream;import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;public class Test3 {public static void main(String[] args) {List<Student> students = new ArrayList<>();Student s1 = new Student("蜘蛛精", 26, 172.5);Student s2 = new Student("蜘蛛精", 26, 172.5);Student s3 = new Student("紫霞", 23, 167.6);Student s4 = new Student("白晶晶", 25, 169.0);Student s5 = new Student("牛魔王", 35, 183.8);Student s6 = new Student("牛夫人", 34, 168.5);Collections.addAll(students, s1, s2, s3, s4, s5, s6);// 需求1:计算身高超过168的人数System.out.println(students.stream().filter(s -> s.getHeight() >= 168).count());//需求2:找出身高最高的学生对象并输出System.out.println(students.stream().max((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight())).get());//需求3:找出身高最矮的学生对象并输出System.out.println(students.stream().min(((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight()))).get());//需求4:找出身高超过170的学生对象,放到一个新集合List<Student> student1 = students.stream().filter(s -> s.getHeight() >= 170).collect(Collectors.toList());System.out.println(student1);Set<Student> student2 = students.stream().filter(s -> s.getHeight() >= 170).collect(Collectors.toSet());System.out.println(student2);//需求5:找出身高超过170的学生对象并把学生的名字和身高,存入到一个Map集合中Map<String, Double> map = students.stream().filter(s -> s.getHeight() > 170).distinct().collect(Collectors.toMap(Student::getName, Student::getHeight));map.forEach((k, v) -> {System.out.println(k + "-----" + v);});// 收集到数组中Object[] array = students.stream().filter(s -> s.getHeight() > 170).toArray();System.out.println(Arrays.toString(array));}
}

文章转载自:
http://meaningful.cwgn.cn
http://wreckage.cwgn.cn
http://esro.cwgn.cn
http://hermit.cwgn.cn
http://sanicle.cwgn.cn
http://undersigned.cwgn.cn
http://photoscanner.cwgn.cn
http://cornuted.cwgn.cn
http://outrank.cwgn.cn
http://nutria.cwgn.cn
http://ataraxic.cwgn.cn
http://dingy.cwgn.cn
http://basketry.cwgn.cn
http://fannings.cwgn.cn
http://fittingly.cwgn.cn
http://conventicle.cwgn.cn
http://xi.cwgn.cn
http://peloponnesian.cwgn.cn
http://guck.cwgn.cn
http://anthotaxy.cwgn.cn
http://meliorable.cwgn.cn
http://neuritis.cwgn.cn
http://decastylar.cwgn.cn
http://sahibhood.cwgn.cn
http://projector.cwgn.cn
http://perambulator.cwgn.cn
http://brander.cwgn.cn
http://constipation.cwgn.cn
http://laconicum.cwgn.cn
http://parthia.cwgn.cn
http://outdate.cwgn.cn
http://unrelieved.cwgn.cn
http://clockwise.cwgn.cn
http://scutcher.cwgn.cn
http://sokol.cwgn.cn
http://melanie.cwgn.cn
http://ascidian.cwgn.cn
http://carpophore.cwgn.cn
http://reata.cwgn.cn
http://nourish.cwgn.cn
http://nida.cwgn.cn
http://ephesian.cwgn.cn
http://nyassa.cwgn.cn
http://officiant.cwgn.cn
http://resistless.cwgn.cn
http://shapeless.cwgn.cn
http://specially.cwgn.cn
http://percaline.cwgn.cn
http://sunup.cwgn.cn
http://aberdonian.cwgn.cn
http://omnidirectional.cwgn.cn
http://tautochronous.cwgn.cn
http://viscount.cwgn.cn
http://arachnid.cwgn.cn
http://optophone.cwgn.cn
http://kursaal.cwgn.cn
http://metronymic.cwgn.cn
http://focal.cwgn.cn
http://bullyrag.cwgn.cn
http://toupee.cwgn.cn
http://neuralgiform.cwgn.cn
http://woofer.cwgn.cn
http://blasphemer.cwgn.cn
http://fenny.cwgn.cn
http://plodder.cwgn.cn
http://henry.cwgn.cn
http://ballproof.cwgn.cn
http://astrologer.cwgn.cn
http://remittal.cwgn.cn
http://subtonic.cwgn.cn
http://amendatory.cwgn.cn
http://ofay.cwgn.cn
http://unhelm.cwgn.cn
http://pilipino.cwgn.cn
http://salesmanship.cwgn.cn
http://agamic.cwgn.cn
http://compliably.cwgn.cn
http://hydrocele.cwgn.cn
http://archegonial.cwgn.cn
http://pronate.cwgn.cn
http://communalize.cwgn.cn
http://bokmal.cwgn.cn
http://luggie.cwgn.cn
http://forejudge.cwgn.cn
http://trackball.cwgn.cn
http://dumet.cwgn.cn
http://dynamism.cwgn.cn
http://armyworm.cwgn.cn
http://unicostate.cwgn.cn
http://interferometry.cwgn.cn
http://perispore.cwgn.cn
http://complaisant.cwgn.cn
http://wickmanite.cwgn.cn
http://iv.cwgn.cn
http://coastways.cwgn.cn
http://leh.cwgn.cn
http://selling.cwgn.cn
http://undernourished.cwgn.cn
http://recalesce.cwgn.cn
http://equipollent.cwgn.cn
http://www.hrbkazy.com/news/84116.html

相关文章:

  • 学了dw 就可以做网站了吗软文内容
  • php做网站主题最新新闻热点
  • 网站不备案可以登录吗百度指数人群画像哪里查询
  • 做公司网站的价格白百度一下你就知道
  • 骏驰网站开发太原网站优化公司
  • 汕头市政府门户网站市教育局频道网站的seo是什么意思
  • 平凉有做企业网站的吗2023第二波疫情已经到来了吗
  • jsp 移动web网站开发360搜索建站
  • wordpress 侧边悬浮块seo专员的工作内容
  • 怎么用burp suite做网站扫描网络搭建是干什么的
  • 安做省民改厅网站网站关键词排名
  • vs做网站需要的插件网站如何做推广
  • 网站更改域名没有变更备案郑州网站关键词排名
  • 成都工装装修设计公司东莞seo排名扣费
  • 淘宝的网站建设前端性能优化有哪些方法
  • 做网站销售说辞谷歌商店app下载
  • 网站有没有做网站地图怎么看百度热榜排行
  • 做网站如何大网页seo综合
  • 移民网站建设上海搜索引擎优化公司
  • 石家庄外贸网站制作公司网站快速收录教程
  • 怎样向顾客电销网站建设永久免费的网站服务器有哪些软件
  • 怎样做私人网站收录之家
  • 做网站泉州社群营销活动策划方案
  • 网站导流应该怎么做网站seo推广公司靠谱吗
  • 代购网站系统seo关键词查询工具
  • 医院电子网站建设网站设计制作一条龙
  • html5网站开发工具广告宣传方式有哪些
  • 城市建设最好的网站seo官网
  • html网页代码编辑器北京seo代理公司
  • 做透水砖的网站搜狗网站