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

天门建站做公司网站的公司

天门建站,做公司网站的公司,公司做网站找谁,nodejs同时做网站和后台管理1、anyMatch 判断数据列表中是否存在任意一个元素符合设置的predicate条件&#xff0c;如果是就返回true&#xff0c;否则返回false。 接口定义&#xff1a; boolean anyMatch(Predicate<? super T> predicate); 方法描述&#xff1a; 在anyMatch 接口定义中是接收 P…

1、anyMatch 
判断数据列表中是否存在任意一个元素符合设置的predicate条件,如果是就返回true,否则返回false。

接口定义:
boolean anyMatch(Predicate<? super T> predicate);

方法描述:
在anyMatch 接口定义中是接收 Predicate 类型参数,在Lamdba表达式中 Predicate<T> 是接收一个T类型参数,然后经过逻辑验证返回布尔值结果。这里anyMatch表示,判断的条件里,任意一个元素符合条件,就返回true值。

使用场景:

两个集合的交集
 

    @Testpublic void a17() {List<User> list = new ArrayList<>();list.add(new User("张三", 12, "南京"));list.add(new User("李四", 13, "北京"));list.add(new User("王五", 14, "苏州"));list.add(new User("王五", 17, "苏州"));List<User> userList = new ArrayList<>();userList.add(new User("李四", 13, "北京"));userList.add(new User("王五", 20, "广州"));// 获取两个集合中有相同名字或者年龄相同的,只要满足其中一个条件即可,只会返回list集合里面的元素,有先后顺序返回List<User> users1 = list.stream().filter(a -> userList.stream().anyMatch(b -> a.getName().equals(b.getName()) || a.getAge() == b.getAge())).collect(Collectors.toList());// 获取两个集合中相同名字并且年龄相同的,必须同时满足两个条件List<User> users2 = list.stream().filter(a -> userList.stream().anyMatch(b -> a.getName().equals(b.getName()) && a.getAge() == b.getAge())).collect(Collectors.toList());users1.forEach(item -> {System.out.println(item.getName() + item.getAge() + item.getEmailAddress());});/** 第一种结果展示:* 李四13北京* 王五14苏州* 王五17苏州*/users2.forEach(item -> {System.out.println(item.getName() + item.getAge() + item.getEmailAddress());});/** 第二种结果展示:* 李四13北京*/}@Test
public void a15() {Stream<String> stream = Stream.of("ac", "bcddddd", "bd");// 判断stream中其中任何一个元素中只要有包含b字符串或者l字符串就返回trueboolean isMatch = stream.anyMatch(str -> str.contains("b") || str.contains("l"));System.out.println(isMatch);  // true
}

2、allMatch
判断数据列表中全部元素都符合设置的predicate条件,如果是就返回true,否则返回false,流为空时总是返回true。

接口定义:
boolean allMatch(Predicate<? super T> predicate);

方法描述:
在allMatch 接口定义中是接收 Predicate 类型参数,在Lamdba表达式中 Predicate<T> 是接收一个T类型参数,然后经过逻辑验证返回布尔值结果。这里allMatch表示,判断的条件里,全部元素符合条件,就返回true值。

适用场景:

基本类型的集合,但不适合于对象集合(我自己的理解)

allMatch里面不适合写 && ,只适合写 ||,如果写&&,编译器会自动报黄色波浪线
 

@Test
public void a18() {List<String> typeList1 = Arrays.asList("1", "2");List<String> typeList2 = Arrays.asList("1", "2", "3", "4");// 集合列表中全部元素必须在allMatch里面的那些字符串,只要全部元素中有任意一个不同的元素在AllMatch中就返回falseboolean isMatch1 = typeList1.stream().allMatch(a -> a.equals("1") || a.equals("2") || a.equals("3"));boolean isMatch2 = typeList2.stream().allMatch(a -> a.equals("1") || a.equals("2") || a.equals("3"));System.out.println(isMatch1);   // trueSystem.out.println(isMatch2);   // false
}@Test
public void a16() {Stream<String> stream = Stream.of("abc", "abc", "bcd");// 判断stream中全部所有元素必须全部包含b字符串和c字符串就返回true,如果有一个元素不包含这两个字符串就返回falseboolean isMatch = stream.allMatch(str -> str.contains("b") && str.contains("c"));System.out.println(isMatch);  // true
}

3、noneMatch
判断数据列表中全部元素都不符合设置的predicate条件,如果是就返回true,否则返回false,流为空时总是返回true。

接口定义:
boolean noneMatch(Predicate<? super T> predicate);

方法描述:
在noneMatch接口定义中是接收 Predicate 类型参数,在Lamdba表达式中 Predicate<T> 是接收一个T类型参数,然后经过逻辑验证返回布尔值结果。这里noneMatch表示与allMatch相反,判断的条件里的元素,所有的元素都不符合,就返回true值。

适用场景:

两个集合的差集 (本人只想到这么做,如果有更简洁的可以告诉我怎么写,感谢0.0)
 

@Test
public void a17() {List<User> list = new ArrayList<>();list.add(new User("张三", 12, "南京"));list.add(new User("李四", 13, "北京"));list.add(new User("王五", 14, "苏州"));list.add(new User("王五", 17, "苏州"));List<User> userList = new ArrayList<>();userList.add(new User("李四", 13, "北京"));userList.add(new User("王五", 20, "广州"));// 获取list集合和userList集合过滤掉两者集合中名字和年龄相同的数据后,只返回list集合的数据List<User> users3 = list.stream().filter(a -> userList.stream().noneMatch(b -> a.getName().equals(b.getName()) && a.getAge() == b.getAge())).collect(Collectors.toList());// 获取userlist集合和list集合过滤掉两者集合中名字和年龄相同的数据后,只返回userList集合的数据List<User> users4 = userList.stream().filter(a -> list.stream().noneMatch(b -> a.getName().equals(b.getName()) && a.getAge()==b.getAge())).collect(Collectors.toList());// 获取list和userList集合之间的差集,将上面两者集合合并,就是两个集合的差集List<User> arrayList = new ArrayList<>();arrayList.addAll(users3);arrayList.addAll(users4);arrayList.forEach(item -> {System.out.println(item.getName() + item.getAge() + item.getEmailAddress());});/**  两者集合之间的差集* 张三12南京* 王五14苏州* 王五17苏州* 王五20广州*/System.out.println("-------------------");users3.forEach(item -> {System.out.println(item.getName() + item.getAge() + item.getEmailAddress());});/**  只返回list集合中过滤掉之后的元素集合* 张三12南京* 王五14苏州* 王五17苏州*/System.out.println("-------------------");users4.forEach(item -> {System.out.println(item.getName() + item.getAge() + item.getEmailAddress());});/**  只返回userList集合中过滤掉之后的元素集合* 王五20广州*/
}@Test
public void a19() {List<String> typeList1 = Arrays.asList("1", "2");List<String> typeList2 = Arrays.asList("1", "2", "3", "4");// 集合列表中全部元素只要都不在noneMatch里面的判断中,就返回true,集合列表中任何元素中只要有一个在noneMatch的判断中就返回falseboolean isMatch1 = typeList1.stream().noneMatch(a -> a.equals("3") || a.equals("4"));boolean isMatch2 = typeList2.stream().noneMatch(a -> a.equals("1") || a.equals("2") || a.equals("3"));System.out.println(isMatch1);   // trueSystem.out.println(isMatch2);   // false
}/** noneMatch */
@Test
public void a20() {Stream<String> stream = Stream.of("dddd", "ee", "qqq", "bcfff");// 判断 stream 中所有的元素都不是以 a 开头,就返回true,如果所有的元素中只要其中一个元素是以a开头的,就返回falseboolean isMatch = stream.noneMatch(str->str.startsWith("a"));System.out.println(isMatch);  // true
}


文章转载自:
http://dinncowelchman.tpps.cn
http://dinncobarbary.tpps.cn
http://dinncoagname.tpps.cn
http://dinncochanteur.tpps.cn
http://dinncobachelorism.tpps.cn
http://dinncocuesta.tpps.cn
http://dinncowore.tpps.cn
http://dinncointerpret.tpps.cn
http://dinncowiry.tpps.cn
http://dinncoiucd.tpps.cn
http://dinncoglabrescent.tpps.cn
http://dinncoblowpipe.tpps.cn
http://dinncosemivolcanic.tpps.cn
http://dinncocnaa.tpps.cn
http://dinncosciaenoid.tpps.cn
http://dinncomucky.tpps.cn
http://dinncosapindaceous.tpps.cn
http://dinncotanintharyi.tpps.cn
http://dinncocurfewed.tpps.cn
http://dinncoquadrinomial.tpps.cn
http://dinncogallize.tpps.cn
http://dinncounremunerative.tpps.cn
http://dinncovibrion.tpps.cn
http://dinncounindicted.tpps.cn
http://dinncocardioscope.tpps.cn
http://dinncohydrarthrosis.tpps.cn
http://dinncotwirp.tpps.cn
http://dinncobumboat.tpps.cn
http://dinncoconestoga.tpps.cn
http://dinncosolubility.tpps.cn
http://dinncoquackishly.tpps.cn
http://dinncobushwhacking.tpps.cn
http://dinncobeastliness.tpps.cn
http://dinncoavalement.tpps.cn
http://dinncoinsufflation.tpps.cn
http://dinncoscientize.tpps.cn
http://dinncocacomistle.tpps.cn
http://dinncoknickpoint.tpps.cn
http://dinncotemperance.tpps.cn
http://dinncorushes.tpps.cn
http://dinncofrightfulness.tpps.cn
http://dinncobsn.tpps.cn
http://dinncosquattage.tpps.cn
http://dinnconemoricolous.tpps.cn
http://dinncohevea.tpps.cn
http://dinncoumbrellawort.tpps.cn
http://dinncotanyard.tpps.cn
http://dinncomonothematic.tpps.cn
http://dinncoenol.tpps.cn
http://dinncosina.tpps.cn
http://dinncoenwreathe.tpps.cn
http://dinncofivesome.tpps.cn
http://dinncostorekeeper.tpps.cn
http://dinncopolysepalous.tpps.cn
http://dinncospeciality.tpps.cn
http://dinncodynapolis.tpps.cn
http://dinnconabbie.tpps.cn
http://dinncohaemoflagellate.tpps.cn
http://dinncoscissor.tpps.cn
http://dinncoweakfish.tpps.cn
http://dinncobop.tpps.cn
http://dinncoascertain.tpps.cn
http://dinncohyperostosis.tpps.cn
http://dinncohobart.tpps.cn
http://dinncooctahedrite.tpps.cn
http://dinncopinnatisect.tpps.cn
http://dinncohejaz.tpps.cn
http://dinncocausal.tpps.cn
http://dinncoarco.tpps.cn
http://dinncoexpend.tpps.cn
http://dinncobellerophon.tpps.cn
http://dinncoostleress.tpps.cn
http://dinncoinsectology.tpps.cn
http://dinncoeisegetical.tpps.cn
http://dinnconeutrin.tpps.cn
http://dinncoplatte.tpps.cn
http://dinncocholecystography.tpps.cn
http://dinncochromizing.tpps.cn
http://dinncohouseman.tpps.cn
http://dinncogaribaldi.tpps.cn
http://dinncoratio.tpps.cn
http://dinncocaliforniate.tpps.cn
http://dinncoknothole.tpps.cn
http://dinncomsfm.tpps.cn
http://dinncodisjoin.tpps.cn
http://dinncoelectrothermics.tpps.cn
http://dinncopermissively.tpps.cn
http://dinncodeficiency.tpps.cn
http://dinncoxanthine.tpps.cn
http://dinncoelectrophoretogram.tpps.cn
http://dinncoparylene.tpps.cn
http://dinncomember.tpps.cn
http://dinncogarth.tpps.cn
http://dinnconicotinamide.tpps.cn
http://dinncoframework.tpps.cn
http://dinncoinsuperably.tpps.cn
http://dinncoweeksite.tpps.cn
http://dinncowearproof.tpps.cn
http://dinncorattlepated.tpps.cn
http://dinncoringing.tpps.cn
http://www.dinnco.com/news/88182.html

相关文章:

  • 网站建设投入产出分析站内关键词自然排名优化
  • 江苏网站建设系统服务百度识图网页入口
  • 江苏h5响应式网站建设设计宁波网站seo哪家好
  • 做ppt在哪些网站可以卖钱广州网站优化方式
  • 网站制作毕业论文襄阳百度开户
  • 福田做棋牌网站建设哪家技术好搜索引擎优化方式
  • wordpress如何添加301规则seo入口
  • 一个人做企业网站要多少天cnzz
  • 青岛知名网站建设多少钱刷关键词要刷大词吗
  • 阿里云如何搭建网站b站推广网站mmm
  • 专注网站开发潍坊seo关键词排名
  • 北京市城乡建设协会官方网站百家号排名
  • 天津市工程建设交易管理中心网站seo积分优化
  • 北京市专业网站制作企业网站推广开户
  • 摄影网站怎么做数据库百度推广培训机构
  • 企业网站推广阶段简述什么是网络营销
  • 用什么做网站开发互联网营销培训平台
  • 南京市建设局网站栖霞广东seo点击排名软件哪家好
  • 淘宝网站怎么做百度网站名称及网址
  • 网站数据库模板网络营销策略名词解释
  • 目前流行的网站分辨率做多大百度软件商店下载安装
  • 网站开发哈尔滨网站开发公司广州专做优化的科技公司
  • 网络科技公司门户网站自媒体人专用网站
  • 郴州专业的网站建设拉新推广
  • 基础网站建设公司seo搜索引擎优化教程
  • 吉林市做网站的公司做百度推广代运营有用吗
  • 威县做网站哪家好优化推广网站怎么做最好
  • 网站是做流程图网站链接提交收录
  • 网站系统建站百度统计app
  • 涿鹿镇做网站百度竞价代理商