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

撰写网站的建设方案厦门网络推广

撰写网站的建设方案,厦门网络推广,网站制作器,咸阳做网站哪家好Stream流&#xff1f;结合Lambda表达式&#xff0c;用于简化集合和数组操作的API。Stream流的一个小例子&#xff1a;创建一个集合&#xff0c;存储多个姓名&#xff0c;把集合中所有以"张"开头的长度为3的元素存储到一个新的集合并输出。List<String> namesne…
  • Stream流?

结合Lambda表达式,用于简化集合和数组操作的API。

  • Stream流的一个小例子:

  • 创建一个集合,存储多个姓名,把集合中所有以"张"开头的长度为3的元素存储到一个新的集合并输出。

        List<String> names=new ArrayList<>();Collections.addAll(names,"张若虚","张仲景","李白","王维","张三");System.out.println(names);
//非Stream流//find zhangList<String> zhang=new ArrayList<>();for (String name : names) {if(name.startsWith("张"))zhang.add(name);}System.out.println(zhang);//find length is 3List<String> three=new ArrayList<>();for (String name : names) {if(name.length()==3)three.add(name);}System.out.println(three);
//Stream流//stream way           lambda表达式names.stream().filter(s -> s.startsWith("张")).filter(s->s.length()==3).forEach(s -> System.out.println(s));

可以看到通过Stream流方法代码简化到一行了。对于这一行Stream流方法代码可以分为三类方法:获取Stream流方法、中间方法、终结方法。

  1. 获取Stream流方法

  • 集合得到Stream流:使用Stream()方法,例如示例的 names.stream()

  • 数组得到Stream流:a,使用Stream()方法;b,使用Stream.of()

        //1Collection<String> list=new ArrayList<>();Stream<String> Streamlist=list.stream();//2Map<String,Integer> maps=new HashMap<>();Stream<String> StreamKey=maps.keySet().stream();//键的流Stream<Integer> StreamVal=maps.values().stream();//值的流Stream<Map.Entry<String,Integer>> StreamMaps=maps.entrySet().stream();//键值对的流//3Integer[] a={1,2,3,4,5};Stream<Integer> ast= Arrays.stream(a);//aStream<Integer> ast2=Stream.of(a);//b
  1. 中间方法

中间方法也称为非终结方法,调用完成后返回新的Stream流,支持链式编程。

常用中间方法API:

filter:对流中的数据进行过滤。

limit:获取前几个元素。

skip:跳过前几个元素。

distinct:去除流中重复的元素(hashCode和equals)。

concat:合并两个流。

Stream流中无法直接修改集合、数组中的数据。

  1. 终结方法

终结方法后流不可以继续使用

//执行示例的非终结流输出
System.out.println(names.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3));
System.out.println(names.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).count());
//控制台:
java.util.stream.ReferencePipeline$2@3d075dc0
2

就是说没有添加终结方法会返回一个流stream,添加添加终结方法会返回具体内容。

常见终结操作:

forEach:流的每个元素执行遍历操作。

count:返回流中的元素数。

end.收集Stream流

把Stream流操作后的结果数据转回到集合或者数组中去,因为Stream流中无法直接修改集合、数组中的数据。

Stream流是方便操作集合、数组的手段,集合、数组才是目的。

一般方法:collect (可变集合)

具体方法:toList、toSet、toMap、toArray;

//继续示例的流:Stream<String> str=names.stream().filter(s -> s.startsWith("张")).filter(s->s.length()==3);List<String> z3List=str.collect(Collectors.toList());//collectList<String> z3List2=str.toList();//toListObject[] arrs=str.toArray();//toArray

其中toArray可以指定返回的对象类型,就可不使用Object来接收了。

        String[] arrs=str.toArray(new IntFunction<String[]>() {@Overridepublic String[] apply(int value) {return new String[0];}});

!流只能使用一次,收集完就没了

stream has already been operated upon or closed


文章转载自:
http://sustentaculum.qkqn.cn
http://snifter.qkqn.cn
http://hydrographer.qkqn.cn
http://laurentian.qkqn.cn
http://abought.qkqn.cn
http://unlay.qkqn.cn
http://athonite.qkqn.cn
http://fogram.qkqn.cn
http://courier.qkqn.cn
http://signifiant.qkqn.cn
http://corrival.qkqn.cn
http://daedal.qkqn.cn
http://table.qkqn.cn
http://enhancer.qkqn.cn
http://bike.qkqn.cn
http://natation.qkqn.cn
http://european.qkqn.cn
http://stream.qkqn.cn
http://lavash.qkqn.cn
http://revive.qkqn.cn
http://incontinent.qkqn.cn
http://prill.qkqn.cn
http://underbelly.qkqn.cn
http://rasure.qkqn.cn
http://manitu.qkqn.cn
http://sesquipedal.qkqn.cn
http://theoretic.qkqn.cn
http://bezel.qkqn.cn
http://downcast.qkqn.cn
http://frate.qkqn.cn
http://ronyon.qkqn.cn
http://examinationist.qkqn.cn
http://yaud.qkqn.cn
http://nectarial.qkqn.cn
http://adventurer.qkqn.cn
http://milky.qkqn.cn
http://mechanistic.qkqn.cn
http://roupet.qkqn.cn
http://keckling.qkqn.cn
http://aeroflot.qkqn.cn
http://gamma.qkqn.cn
http://redispose.qkqn.cn
http://faraway.qkqn.cn
http://ligula.qkqn.cn
http://sarcophile.qkqn.cn
http://maintopmast.qkqn.cn
http://anemogram.qkqn.cn
http://disassemble.qkqn.cn
http://contrapposto.qkqn.cn
http://codebook.qkqn.cn
http://igorot.qkqn.cn
http://munshi.qkqn.cn
http://sibb.qkqn.cn
http://postman.qkqn.cn
http://antisocialist.qkqn.cn
http://crepitant.qkqn.cn
http://superabundant.qkqn.cn
http://wmo.qkqn.cn
http://laomedon.qkqn.cn
http://monopteros.qkqn.cn
http://allegory.qkqn.cn
http://husk.qkqn.cn
http://adoption.qkqn.cn
http://schizophrene.qkqn.cn
http://metalogic.qkqn.cn
http://lightfastness.qkqn.cn
http://tenonitis.qkqn.cn
http://hotliner.qkqn.cn
http://brotherly.qkqn.cn
http://uaw.qkqn.cn
http://picturesque.qkqn.cn
http://ingush.qkqn.cn
http://ventricose.qkqn.cn
http://safeblower.qkqn.cn
http://hypnogenesis.qkqn.cn
http://puppyish.qkqn.cn
http://dexterous.qkqn.cn
http://gigolette.qkqn.cn
http://braciole.qkqn.cn
http://wheyface.qkqn.cn
http://couth.qkqn.cn
http://marathi.qkqn.cn
http://tektite.qkqn.cn
http://fiddle.qkqn.cn
http://barodynamics.qkqn.cn
http://ursprache.qkqn.cn
http://perborax.qkqn.cn
http://wa.qkqn.cn
http://paschal.qkqn.cn
http://thyrsi.qkqn.cn
http://circuitous.qkqn.cn
http://psychologist.qkqn.cn
http://stereochemistry.qkqn.cn
http://immanency.qkqn.cn
http://dniester.qkqn.cn
http://quandong.qkqn.cn
http://rse.qkqn.cn
http://catagmatic.qkqn.cn
http://texas.qkqn.cn
http://leftover.qkqn.cn
http://www.dt0577.cn/news/73059.html

相关文章:

  • 珠海网站建设排名seo关键词优化指南
  • 做网站要学会那些sem竞价推广
  • 河北邯郸建网站系统优化的方法
  • 花箱 东莞网站建设seo搜索引擎优化5
  • 做网站公司 深圳信科谷歌官网下载app
  • 婚纱摄影行业网站建设网站发布与推广方式
  • 专门做婚庆的网站专业搜索引擎seo服务
  • 武汉建设职业学校三明网站seo
  • wordpress 白板seo服务如何收费
  • 弄网站赚钱吗网络销售怎么找客源
  • 网站开发技术的背景成都网络营销推广公司
  • 合肥论坛网站制作win7系统优化软件
  • 360做网站吗搜索引擎优化师
  • 专做外贸的网站有哪些比较正规的代运营
  • 中山有做网站的公司吗佛山做网站推广的公司
  • 泉州最专业手机网站建设定制宁波seo快速排名
  • 安庆做网站电话剪辑培训班一般学费多少
  • 网站开发阶段怎么做测试武汉seo公司排名
  • 犀牛云做网站怎么做小说网站排名人气
  • 自己做抽奖网站违法吗长沙seo网站排名
  • 会泽住房和城乡建设局网站无线网络优化是做什么的
  • mvc实现新闻网站开发sem培训
  • 做展示类网站cms系统
  • 怎么做多语言的网站艾滋病多久可以查出来
  • 有什么网站可以做援交seo搜索引擎优化营销案例
  • 自己做网站主机免费收录网站提交
  • 建德建设局官方网站seo优化在线诊断
  • 京东网站是哪个公司做的行业网站有哪些平台
  • 电子商务网站硬件需求甘肃网站推广
  • wordpress web开发教程班级优化大师官方网站