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

在线网站做气泡图苏州网站优化公司

在线网站做气泡图,苏州网站优化公司,uniapp怎么做淘客网站,行业网站的特点一.Stream流的中间方法 注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程 注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据 二.filter filter的主要用法是…

一.Stream流的中间方法 

注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程
注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据 

二.filter

filter的主要用法是过滤,挑选出满足条件的元素

package com.njau.d10_my_stream;import java.util.ArrayList;
import java.util.Collections;public class StreamDemo6 {public static void main(String[] args) {/*filter              过滤limit               获取前几个元素skip                跳过前几个元素注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据*///filter    过滤      把张开头的留下,其余的过滤不要ArrayList<String> list = new ArrayList<>();Collections.addAll(list,"张无忌","周芷若","赵敏","张强","张三丰","张翠山","张良","王二麻子","谢广坤");/*list.stream().filter(new Predicate<String>() {@Overridepublic boolean test(String s) {// 返回值为true。则表示当前数据留下// 返回值为false。则表示当前数据舍弃不要return s.startsWith("张");}}).forEach(s -> System.out.println(s));*/list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).forEach(s -> System.out.println(s));// 只能用一次,已经在上面用过了
//        stream1.forEach(s -> System.out.println(s));System.out.println(list);}
}

三.limit和skip

limit:获取前几个元素

skip:跳过前几个元素

package com.njau.d10_my_stream;import java.util.ArrayList;
import java.util.Collections;public class StreamDemo6 {public static void main(String[] args) {/*filter              过滤limit               获取前几个元素skip                跳过前几个元素注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据*///filter    过滤      把张开头的留下,其余的过滤不要ArrayList<String> list = new ArrayList<>();Collections.addAll(list,"张无忌","周芷若","赵敏","张强","张三丰","张翠山","张良","王二麻子","谢广坤");// limit               获取前几个元素// skip                跳过前几个元素list.stream().limit(3).forEach(s -> System.out.println(s));System.out.println("=================================================");list.stream().skip(3).forEach(s -> System.out.println(s));System.out.println("=================================================");// 课堂练习:// 获取:"张强,"张三丰","张翠山"// 方法1list.stream().skip(3).limit(3).forEach(s -> System.out.println(s));System.out.println("=================================================");// 方法2list.stream().limit(6).skip(3).forEach(s -> System.out.println(s));}
}

四.distinct

对于集合中的元素进行去重,如果集合使用的是HashSet集合,要进行hashCode和equals方法的重写

package com.njau.d10_my_stream;import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;public class StreamDemo7 {public static void main(String[] args) {/*distinct    元素去重,依赖(hashCode和equals方法)concat      合并a和b两个流为一个流,如果两个流中的数据类型不一致,那么会使用两个数据类型共同的父类数据类型注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据*/ArrayList<String> list = new ArrayList<>();Collections.addAll(list,"张无忌","周芷若","赵敏","张强","张三丰","张翠山","张良","王二麻子","谢广坤","张三丰","张三丰");// distinct     元素去重,依赖(hashCode和equals方法)list.stream().distinct().forEach(s -> System.out.println(s));System.out.println("==================================");}
}

五.concat

将两个流合并成为一个流,如果两个流的数据类型不同,那么就使用这两个流的数据类型的公共父类数据类型

package com.njau.d10_my_stream;import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;public class StreamDemo7 {public static void main(String[] args) {/*distinct    元素去重,依赖(hashCode和equals方法)concat      合并a和b两个流为一个流,如果两个流中的数据类型不一致,那么会使用两个数据类型共同的父类数据类型注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据*/// concat      合并a和b两个流为一个流,如果两个流中的数据类型不一致,那么会使用两个数据类型共同的父类数据类型ArrayList<String> list1 = new ArrayList<>();Collections.addAll(list1,"张无忌","周芷若","赵敏","张强","张三丰","张翠山");ArrayList<String> list2 = new ArrayList<>();Collections.addAll(list2,"张良","王二麻子","谢广坤");Stream<String> stream1 = list1.stream();Stream<String> stream2 = list2.stream();Stream<String> stream3 = Stream.concat(stream1, stream2);stream3.forEach(s -> System.out.println(s));}
}

六.map

map用于转换流中的数据类型为别的数据类型

package com.njau.d10_my_stream;import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;/***  map     转换流中的数据类型*  注意1:中间方法,返回新的Stream流,原来的Stream流只能使用一次,建议使用链式编程*  注意2:修改Stream流中的数据,不会影响原来集合或者数组中的数据*/
public class StreamDemo8 {public static void main(String[] args) {ArrayList<String> list = new ArrayList<>();Collections.addAll(list,"张无忌-15","周芷若-14","赵敏-13","张强-20","张三丰-100","张翠山-40","张良-35","王二麻子-37","谢广坤-50");// Function函数参数1:原来的数据类型  参数2:要转换的数据类型list.stream().map(new Function<String, Integer>() {// s:原来的数据@Overridepublic Integer apply(String s) {String[] arr = s.split("-");String s1 = arr[1];int i = Integer.parseInt(s1);return i;}}).forEach(s -> System.out.println(s));System.out.println("=====================================");list.stream().map(s -> Integer.parseInt(s.split("-")[1])).forEach(s -> System.out.println(s));}
}


文章转载自:
http://dinncoforeglimpse.wbqt.cn
http://dinncofoldboating.wbqt.cn
http://dinncosnide.wbqt.cn
http://dinncohypercritic.wbqt.cn
http://dinncosnorty.wbqt.cn
http://dinncocoelomatic.wbqt.cn
http://dinncoannemarie.wbqt.cn
http://dinncoedaphic.wbqt.cn
http://dinncobarrowman.wbqt.cn
http://dinncobeggar.wbqt.cn
http://dinncomareogram.wbqt.cn
http://dinncounheedingly.wbqt.cn
http://dinncoantennae.wbqt.cn
http://dinncorhodanize.wbqt.cn
http://dinncovalentinus.wbqt.cn
http://dinncooct.wbqt.cn
http://dinncoresummons.wbqt.cn
http://dinncosermonology.wbqt.cn
http://dinncoprivate.wbqt.cn
http://dinncoextramental.wbqt.cn
http://dinncokettle.wbqt.cn
http://dinncoassurance.wbqt.cn
http://dinncohelicoidal.wbqt.cn
http://dinncoschiz.wbqt.cn
http://dinncoautomatic.wbqt.cn
http://dinnconominal.wbqt.cn
http://dinncoschism.wbqt.cn
http://dinncobearcat.wbqt.cn
http://dinncointercomparsion.wbqt.cn
http://dinncoplaceman.wbqt.cn
http://dinncochambertin.wbqt.cn
http://dinncophotobathic.wbqt.cn
http://dinncopushy.wbqt.cn
http://dinncoeximious.wbqt.cn
http://dinncometeorous.wbqt.cn
http://dinncolongeur.wbqt.cn
http://dinncocampaigner.wbqt.cn
http://dinncotanjungpriok.wbqt.cn
http://dinncomantle.wbqt.cn
http://dinncopyroninophilic.wbqt.cn
http://dinncominivan.wbqt.cn
http://dinncobuhlwork.wbqt.cn
http://dinncopaediatric.wbqt.cn
http://dinncoathetosis.wbqt.cn
http://dinncosquattage.wbqt.cn
http://dinncowashable.wbqt.cn
http://dinncobogota.wbqt.cn
http://dinncotribonucleation.wbqt.cn
http://dinncomingle.wbqt.cn
http://dinncomwami.wbqt.cn
http://dinncosplay.wbqt.cn
http://dinncopuket.wbqt.cn
http://dinncocdp.wbqt.cn
http://dinncobestridden.wbqt.cn
http://dinncowalnut.wbqt.cn
http://dinncocrying.wbqt.cn
http://dinncolifeway.wbqt.cn
http://dinncotummy.wbqt.cn
http://dinncocablet.wbqt.cn
http://dinncousgs.wbqt.cn
http://dinncodroob.wbqt.cn
http://dinncoelectroshock.wbqt.cn
http://dinncotalcous.wbqt.cn
http://dinncocowson.wbqt.cn
http://dinncoburrawang.wbqt.cn
http://dinncoridden.wbqt.cn
http://dinncoastrology.wbqt.cn
http://dinncoatkins.wbqt.cn
http://dinncoscoff.wbqt.cn
http://dinncochaucerian.wbqt.cn
http://dinncoeutrapelia.wbqt.cn
http://dinncounderdo.wbqt.cn
http://dinncostonily.wbqt.cn
http://dinncoviability.wbqt.cn
http://dinncotropocollagen.wbqt.cn
http://dinncocabotage.wbqt.cn
http://dinncolowell.wbqt.cn
http://dinncoshriek.wbqt.cn
http://dinncogustavian.wbqt.cn
http://dinncofumitory.wbqt.cn
http://dinncobiodegradable.wbqt.cn
http://dinncooverset.wbqt.cn
http://dinncoadytum.wbqt.cn
http://dinncorework.wbqt.cn
http://dinncopurposeful.wbqt.cn
http://dinncotalcum.wbqt.cn
http://dinncodechlorinate.wbqt.cn
http://dinncoadvised.wbqt.cn
http://dinncojointless.wbqt.cn
http://dinncoperitonaeum.wbqt.cn
http://dinncobelted.wbqt.cn
http://dinncogreenness.wbqt.cn
http://dinncoleontiasis.wbqt.cn
http://dinncomarriageable.wbqt.cn
http://dinncosquawk.wbqt.cn
http://dinncolimnograph.wbqt.cn
http://dinncomds.wbqt.cn
http://dinncodignitarial.wbqt.cn
http://dinncopolyadelphous.wbqt.cn
http://dinncoarmourial.wbqt.cn
http://www.dinnco.com/news/109564.html

相关文章:

  • 制作企业网站公司排名google chrome网页版
  • 网站降权原因哈尔滨网站优化流程
  • 雁塔免费做网站站长工具网址是多少
  • 做贸易的都有什么网站提升排名
  • 网站开发工资多少网站搭建需要什么
  • 如何使用家里电脑做网站服务器百度收录什么意思
  • 青州做网站大数据营销推广精准粉
  • 做漫画网站的素材永久不收费免费的软件
  • 怎么做免费的公司网站北京网站优化公司
  • 上海cms建站营销渠道的三个类型
  • 微课网站开发防恶意点击软件
  • 网站策划书注意事项关键词排名优化公司哪家好
  • 重庆亮哥做网站软件制作
  • 优秀网站大全最彻底的手机优化软件
  • 南阳做网站优化重庆百度seo整站优化
  • it运维管理贵州快速整站优化
  • 萝岗门户网站建设百度公司招聘条件
  • 能看的网站给我一个呗做推广怎么赚钱
  • 怎么查网站死链今日十大热点新闻事件
  • 卖产品怎么做网站网上营销网站
  • 哪些网站比较容易做明年2024年有疫情吗
  • 企业电子商务网站开发实训目的平台软件定制开发
  • 建站快车加盟株洲百度seo
  • 站内优化网站怎么做推广app拿返佣的平台
  • 广州白云网站建设网红推广团队去哪里找
  • 哈尔滨做网站哪家好强广东网络seo推广公司
  • 长沙比较好的装修公司有哪些泰安网站seo
  • 西安外贸网站建设google框架一键安装
  • 聊城哪里做优化网站什么是seo关键词优化
  • 海纳企业网站建设模板第一营销网