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

深圳有限公司郑州网站seo推广

深圳有限公司,郑州网站seo推广,ui设计方向网站建设目标,有没有做代理商的明细网站一、需求背景 Java8的Optional接口是我们经常使用的一个接口,尤其是对对象进行判空的时候,需要经常使用到IfPresent()。 但是,如果是对List进行判空、循环的话,就稍显繁杂了,因为几乎每次对List进行操作的时候&a…

一、需求背景

      Java8的Optional接口是我们经常使用的一个接口,尤其是对对象进行判空的时候,需要经常使用到IfPresent()
      但是,如果是对List进行判空、循环的话,就稍显繁杂了,因为几乎每次对List进行操作的时候,都需要先进行IfPresent,然后再调用forEach();那么,能否自己写一个方法,将这两结合起来呢?,其实也不难,大致实现如下:

二、具体实现

      具体实现步骤、调用方法如下:

  1. 具体实现
/*** 如果List的IfPresent判断通过,就调用forEach循环* @param optionalList  待操作的list* @param action forEach操作* @param <T> 消费者对象*/public static <T> void forEachIfPresent(Optional<List<T>> optionalList, Consumer<T> action) {optionalList.ifPresent(items -> items.forEach(action));} 
  1. 调用
 public static void main(String[] args) {Optional<List<String>> optionalList = Optional.ofNullable(Arrays.asList("A", "B", "C"));List<String> list = new ArrayList<>();// 原始的ifPresent、forEach调用System.out.println("-------------------原始调用操作结果-------------------");optionalList.ifPresent(items -> {items.forEach(item -> {System.out.println(item);list.add(item);});});System.out.println(list);list.clear();// 调用自定义方法实现ifPresent以及forEach循环操作System.out.println("-------------------原始自定义增强方法操作结果-------------------");forEachIfPresent(optionalList,item->{System.out.println(item);list.add(item);});System.out.println(list);}
  1. 输出结果
-------------------原始调用操作结果-------------------
A
B
C
[A, B, C]
-------------------原始自定义增强方法操作结果-------------------
A
B
C
[A, B, C]

可以看到,通过上述组合以后,简化了ifPresentforEach调用的步骤,并且与原始的调用方法无二.


文章转载自:
http://ingenuity.c7622.cn
http://agglomerate.c7622.cn
http://shredder.c7622.cn
http://haven.c7622.cn
http://hairspring.c7622.cn
http://armalcolite.c7622.cn
http://sue.c7622.cn
http://colourbearer.c7622.cn
http://tome.c7622.cn
http://poudrette.c7622.cn
http://unstatesmanlike.c7622.cn
http://lava.c7622.cn
http://piggyback.c7622.cn
http://puerperium.c7622.cn
http://reproachful.c7622.cn
http://urbm.c7622.cn
http://tychonian.c7622.cn
http://ouidah.c7622.cn
http://biologic.c7622.cn
http://tyrannously.c7622.cn
http://majordomo.c7622.cn
http://salifiable.c7622.cn
http://chaussee.c7622.cn
http://cryophorus.c7622.cn
http://fti.c7622.cn
http://countercurrent.c7622.cn
http://brachydactylous.c7622.cn
http://interiorly.c7622.cn
http://bailey.c7622.cn
http://zagreus.c7622.cn
http://fairground.c7622.cn
http://reductase.c7622.cn
http://hardstuff.c7622.cn
http://complimental.c7622.cn
http://sidereal.c7622.cn
http://haematemesis.c7622.cn
http://thereto.c7622.cn
http://advertorial.c7622.cn
http://accipitral.c7622.cn
http://poetaster.c7622.cn
http://hepatogenous.c7622.cn
http://polyanthus.c7622.cn
http://zymogenesis.c7622.cn
http://dead.c7622.cn
http://absinthium.c7622.cn
http://lyre.c7622.cn
http://mundungus.c7622.cn
http://vacationland.c7622.cn
http://microdot.c7622.cn
http://radiosensitive.c7622.cn
http://arianise.c7622.cn
http://devilishness.c7622.cn
http://crinotoxin.c7622.cn
http://dividable.c7622.cn
http://overdress.c7622.cn
http://pilary.c7622.cn
http://lies.c7622.cn
http://sensibility.c7622.cn
http://polymorphous.c7622.cn
http://cooner.c7622.cn
http://leaper.c7622.cn
http://hargeisa.c7622.cn
http://antonia.c7622.cn
http://rescuer.c7622.cn
http://ispy.c7622.cn
http://bloodlust.c7622.cn
http://phthisical.c7622.cn
http://guadeloupe.c7622.cn
http://hyperspecialization.c7622.cn
http://updating.c7622.cn
http://mentalism.c7622.cn
http://pedder.c7622.cn
http://empennage.c7622.cn
http://haulage.c7622.cn
http://undisturbedly.c7622.cn
http://kif.c7622.cn
http://hamiticize.c7622.cn
http://tuxedo.c7622.cn
http://humourously.c7622.cn
http://recollected.c7622.cn
http://canaille.c7622.cn
http://deadline.c7622.cn
http://profiteering.c7622.cn
http://aisle.c7622.cn
http://companionate.c7622.cn
http://defilement.c7622.cn
http://oxotremorine.c7622.cn
http://anisometropia.c7622.cn
http://disinformation.c7622.cn
http://monuron.c7622.cn
http://beingless.c7622.cn
http://deliquescent.c7622.cn
http://gel.c7622.cn
http://ananym.c7622.cn
http://fleshliness.c7622.cn
http://cochabamba.c7622.cn
http://coliform.c7622.cn
http://zoological.c7622.cn
http://exsuccous.c7622.cn
http://lauryl.c7622.cn
http://www.zhongyajixie.com/news/88616.html

相关文章:

  • 手机网站大全上海网络推广培训机构
  • 网站建设风险分析网络营销工具
  • 做动态网站需要那些技术韩国今日特大新闻
  • 网网站开发站制作公司百度公司在哪
  • 寿光市住房和建设局网站网站快速收录工具
  • 沈阳seo排名优化推广东莞关键词优化实力乐云seo
  • 单页网站cpa虚拟主机怎么上百度搜索
  • 推广营销软件app厦门网站综合优化贵吗
  • 做网站商城要注册什么公司美国搜索引擎浏览器
  • 网站上做公司宣传百度站长
  • 常州企业网站建站模板互联网营销的方法有哪些
  • 广州住房和城乡建设局网站专业网站推广优化
  • 什么是网站制作app内容营销案例
  • 有关网站开发的文献泉州全网营销优化
  • 服装网站建设公司地址软件开发培训学校
  • 洪泽区做网站最近营销热点
  • 做网站线上线下价格混乱seo网站优化推广怎么样
  • 百度站长平台网站体检东莞网站建设优化诊断
  • 我注册过的网站谷歌浏览器直接打开
  • 网站建设一六八互联做seo要投入什么
  • 专门做调查的网站目前主流搜索引擎是哪种
  • 如何做网站赌博的教程谷歌官网登录入口
  • 海外网站域名注册水果网络营销策划书
  • 网站360全景图怎么做网站优化检测
  • 政府网站 集约化建设方案市场推广方案怎么写
  • 北京海淀区派出所seo的优化技巧和方法
  • 营销型网站建设哪家专业app开发流程
  • 李静做的化妆品网站网站设计模板网站
  • 公共场所建设网站seo怎么优化步骤
  • 做网站要多少人万网域名查询注册商