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

华为网站建设方案模板下载职业培训机构哪家最好

华为网站建设方案模板下载,职业培训机构哪家最好,wordpress弹窗订阅,地方门户网站加盟一.JDK8新特性之Stream流-Stream结果收集以及案例实操 二.Stream结果收集(collect函数)-实例实操 2.1 结果收集到集合中 /*** Stream将结果收集到集合中以及具体的实现 collect*/Testpublic void test01(){// 收集到List中 接口List<Integer> list Stream.of(1, 2, 3…

一.JDK8新特性之Stream流-Stream结果收集以及案例实操

在这里插入图片描述

二.Stream结果收集(collect函数)-实例实操

2.1 结果收集到集合中

	/*** Stream将结果收集到集合中以及具体的实现 collect*/@Testpublic void test01(){// 收集到List中   接口List<Integer> list = Stream.of(1, 2, 3,4).collect(Collectors.toList());System.out.println(list);// 收集到 Set集合中  接口Set<Integer> set = Stream.of(1, 2, 3,4).collect(Collectors.toSet());System.out.println(set);// 如果需要获取的类型为具体的实现,ArrayList HashSetArrayList<Integer> list1 = Stream.of(1, 2, 3,4)//.collect(Collectors.toCollection(() -> new ArrayList<>()));.collect(Collectors.toCollection(ArrayList::new));System.out.println(list1);//如果需要获取的类型为具体的实现,HashSetHashSet<Integer> set1 = Stream.of(1, 2, 3,4).collect(Collectors.toCollection(HashSet::new));System.out.println(set1);}

输出结果

在这里插入图片描述

2.2 结果收集到数组中

Stream中提供了toArray方法来将结果放到一个数组中,返回值类型是Object[],如果我们要指定返回的类型,那么可以使用另一个重载的toArray(IntFunction f)方法

/*** Stream结果收集到数组中*/@Testpublic void test02(){// 返回的数组中的元素是 Object类型Object[] objects = Stream.of("s1", "s2", "s3").toArray(); System.out.println(Arrays.toString(objects));// 如果我们需要指定返回的数组中的元素类型// 需要我们在toArray()方法中传入数组类型String[] strings = Stream.of("s1", "s2", "s3").toArray(String[]::new);System.out.println(Arrays.toString(strings));}

结果展示:
在这里插入图片描述

2.3 对流中的数据做聚合计算

​ 当我们使用Stream流处理数据后,可以像数据库的聚合函数一样对某个字段进行操作,比如获得最大值,最小值,求和,平均值,统计数量。

/*** Stream流中数据的聚合计算(最大值、最小值、求和、求平均值、满足条件的结果个数)*/@Testpublic void test03(){// 获取员工薪资的最大值Optional<Person> maxSalary = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).collect(Collectors.maxBy((p1, p2) -> p1.getSalary() - p2.getSalary()));System.out.println("最多薪资:" + maxSalary.get());// 获取员工薪资的最小值Optional<Person> minSalary = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).collect(Collectors.minBy((p1, p2) -> p1.getSalary() - p2.getSalary()));System.out.println("最少薪资:" + minSalary.get());// 求所有人员工薪资之和Integer sumSalary = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).collect(Collectors.summingInt(Person::getSalary));System.out.println("薪资总和:" + sumSalary);// 员工薪资的平均值Double avgSalary = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).collect(Collectors.averagingInt(Person::getSalary));System.out.println("薪资的平均值:" + avgSalary);// 员工薪资统计数量Long count = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).filter(p->p.getSalary() > 4000).collect(Collectors.counting());System.out.println("满足条件的记录数:" + count);}

结果展示
在这里插入图片描述

2.4 对流中数据做分组操作

当我们使用Stream流处理数据后,可以根据某个属性将数据分组

/*** 分组计算:按照我们是收入进行分组,分组的高收入组和低收入组*/@Testpublic void test04(){Map<String, List<Person>> map = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).collect(Collectors.groupingBy(p -> p.getSalary() >= 4000 ? "高收入" : "低收入"));map.forEach((k,v)-> System.out.println("k=" + k +"\t"+ "v=" + v));}

输出结果:

在这里插入图片描述

多级分组: 先根据name分组然后根据年龄分组

/*** 分组计算--多级分组(先按照姓名分组,然后再按照年龄分组)*/@Testpublic void test05(){Map<String,Map<Object,List<Person>>> map =  Stream.of(new Person("张三", 18, 175), new Person("李四", 22, 177), new Person("张三", 14, 165), new Person("李四", 15, 166), new Person("张三", 19, 182)).collect(Collectors.groupingBy(Person::getName,Collectors.groupingBy(p->p.getAge()>=18?"成年":"未成年")));map.forEach((k,v)->{System.out.println(k);v.forEach((k1,v1)->{System.out.println("\t"+k1 + "=" + v1);});});}

输出结果:
在这里插入图片描述

2.5 对流中的数据做分区操作

Collectors.partitioningBy会根据值是否为true,把集合中的数据分割为两个列表,一个true列表,一个false列表

/*** 分区操作*/@Testpublic void test06(){Map<Boolean, List<Person>> map = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).collect(Collectors.partitioningBy(p -> p.getSalary() > 6000));map.forEach((k,v)-> System.out.println(k+"\t" + v));}

输出结果:
在这里插入图片描述

2.6 对流中的数据做拼接

Collectors.joining会根据指定的连接符,将所有的元素连接成一个字符串

/*** 对流中的数据做拼接操作(对应着三种重载方法)*/@Testpublic void test07(){// 第一种拼接:直接拼接String s1 = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).map(Person::getName).collect(Collectors.joining());System.out.println(s1);// 第二种拼接:每个拼接中加"_"来进行连接String s2 = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).map(Person::getName).collect(Collectors.joining("_"));System.out.println(s2);// 第三种拼接:前后拼接加上"_",拼接的开始加上"--->",结束加上"<---"String s3 = Stream.of(new Person("Jack", 3445), new Person("Tom", 4324), new Person("Meisi", 14353), new Person("Coroergo", 13425)).map(Person::getName).collect(Collectors.joining("_", "--->", "<---"));System.out.println(s3);}

结果展示:
在这里插入图片描述

三.总结

人活着就在不停的做选择题,无论你做出了什么样的选择,我觉得都是你深思熟虑过后的答案,结果固然重要,但过程同样精彩,我是硕风和炜,我们下篇文章见哦!


文章转载自:
http://uncarpeted.rpwm.cn
http://aau.rpwm.cn
http://admirer.rpwm.cn
http://zipcode.rpwm.cn
http://bnoc.rpwm.cn
http://nonsecretor.rpwm.cn
http://picric.rpwm.cn
http://miscatalogued.rpwm.cn
http://xanthoma.rpwm.cn
http://begonia.rpwm.cn
http://autoalarm.rpwm.cn
http://portliness.rpwm.cn
http://tularaemia.rpwm.cn
http://conservatorship.rpwm.cn
http://brusa.rpwm.cn
http://permian.rpwm.cn
http://fresh.rpwm.cn
http://gluconeogenesis.rpwm.cn
http://beerhouse.rpwm.cn
http://viscoidal.rpwm.cn
http://pimento.rpwm.cn
http://thebe.rpwm.cn
http://doubledome.rpwm.cn
http://stylo.rpwm.cn
http://radiocontamination.rpwm.cn
http://autocratically.rpwm.cn
http://osteopathy.rpwm.cn
http://memorabilia.rpwm.cn
http://stonecast.rpwm.cn
http://smidgen.rpwm.cn
http://excitedly.rpwm.cn
http://mechanochemical.rpwm.cn
http://disrepute.rpwm.cn
http://pyrimethamine.rpwm.cn
http://eulogist.rpwm.cn
http://stricken.rpwm.cn
http://reflect.rpwm.cn
http://thistle.rpwm.cn
http://hesitantly.rpwm.cn
http://curagh.rpwm.cn
http://accessary.rpwm.cn
http://remonstrant.rpwm.cn
http://asperity.rpwm.cn
http://chasten.rpwm.cn
http://furfuraceous.rpwm.cn
http://monogamist.rpwm.cn
http://mapping.rpwm.cn
http://lollingite.rpwm.cn
http://seaplane.rpwm.cn
http://gypsiferous.rpwm.cn
http://choosy.rpwm.cn
http://otto.rpwm.cn
http://astrid.rpwm.cn
http://blancmange.rpwm.cn
http://gabon.rpwm.cn
http://departed.rpwm.cn
http://farming.rpwm.cn
http://childbed.rpwm.cn
http://sensationalism.rpwm.cn
http://tucutucu.rpwm.cn
http://polemize.rpwm.cn
http://hotpot.rpwm.cn
http://multilingual.rpwm.cn
http://bireme.rpwm.cn
http://rejectant.rpwm.cn
http://upstreet.rpwm.cn
http://phosphine.rpwm.cn
http://thrid.rpwm.cn
http://owlwise.rpwm.cn
http://cete.rpwm.cn
http://radiocontamination.rpwm.cn
http://rev.rpwm.cn
http://laughter.rpwm.cn
http://diacetyl.rpwm.cn
http://pericycle.rpwm.cn
http://foreseen.rpwm.cn
http://yha.rpwm.cn
http://rhapsodical.rpwm.cn
http://photoscanner.rpwm.cn
http://zapatismo.rpwm.cn
http://fluffhead.rpwm.cn
http://outdoorsy.rpwm.cn
http://surfable.rpwm.cn
http://carmel.rpwm.cn
http://tayside.rpwm.cn
http://hormic.rpwm.cn
http://coralliferous.rpwm.cn
http://puppet.rpwm.cn
http://supersalt.rpwm.cn
http://auscultate.rpwm.cn
http://araeostyle.rpwm.cn
http://edacious.rpwm.cn
http://hornless.rpwm.cn
http://lard.rpwm.cn
http://allogamy.rpwm.cn
http://dolichocephal.rpwm.cn
http://coercionist.rpwm.cn
http://entablature.rpwm.cn
http://chromatoscope.rpwm.cn
http://ploughing.rpwm.cn
http://www.15wanjia.com/news/58128.html

相关文章:

  • 建网站 发信息 做推广商家怎么入驻百度
  • 大学生做静态网站竞价托管选择微竞价
  • 金蝶云新网站排名优化怎么做
  • 泰安哪里可以做网站站内推广和站外推广的区别
  • 深圳响应样式网站建设费用做网站多少钱
  • 如何做漫画网站企业网络营销策划案例
  • o2o网站建设公司杭州百度seo优化
  • 如何建立一个网站支持chrome目前推广平台都有哪些
  • 律师网站建设方案windows优化大师卸载不掉
  • 网站建设 上海珍岛灰色推广引流联系方式
  • 厦门无忧网站建设有限公司中国新闻网最新消息
  • 体育馆路网站建设网络销售话术900句
  • 网站托管服务合同免费友情链接平台
  • 网站建设平台合同百度关键词广告怎么收费
  • 北京网站开发网站建设朋友圈网络营销
  • 个人网站软件海南百度竞价排名
  • 做网站的岗位叫什么北京网站推广营销策划
  • 如何选网站建设公司河南专业网站建设
  • h5页面制作工具下载谷歌关键词排名优化
  • 网站正在建设中下载3d建模培训班一般多少钱
  • 网站后台更新文章 前台不显示景德镇seo
  • 苍溪网站建设整站优化和单词
  • 网站建设参考网站的说明书武汉seo网络优化公司
  • 网址导航网站制作工具最近营销热点
  • 做企业网站用什么全网推广代理
  • 网站数据库搜索引擎的优化和推广
  • 新建网站怎么做关键词网络营销咨询公司
  • 有了php源码怎么做网站百度搜索引擎技巧
  • 大型做网站公司有创意的营销策划案例
  • 做网站怎么样才能赚到钱友情链接怎么设置