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

响应式网站设计思路徐州网站建设方案优化

响应式网站设计思路,徐州网站建设方案优化,巢湖路桥建设集团有限公司网站,自己做网站nas应用场景: 第一次程序员A写好了个基础的遍历方法: public class Demo1 {public static void main(String[] args) {//假设main方法为程序员B写的,此时需要去调用A写好的一个遍历方法//1.如果此时B突然发现想将字符串以小写的形式打印出来,则…

 应用场景:

第一次程序员A写好了个基础的遍历方法:

public class Demo1 {public static void main(String[] args) {//假设main方法为程序员B写的,此时需要去调用A写好的一个遍历方法//1.如果此时B突然发现想将字符串以小写的形式打印出来,则去请求A修改LinkedList<String > list=new LinkedList<>();list.add("Acb");list.add("Vudh");list.add("hsuU");print(list);}//A程序员写的遍历方法public static void print(LinkedList<String> list){for (String s : list) {System.out.println(s);}}
}

 第二次程序员A完成了字符转小写的遍历方法:

 public static void main(String[] args) {//假设main方法为程序员B写的,此时需要去调用A写好的一个遍历方法//1.如果此时B突然发现想将字符串以小写的形式打印出来,则去请求A修改LinkedList<String > list=new LinkedList<>();list.add("Acb");list.add("Vudh");list.add("hsuU");print(list);}//A程序员写的遍历方法public static void print(LinkedList<String> list){for (String s : list) {System.out.println(s.toLowerCase());}}

第三次程序员A直接将接口调用给了B,B可以根据需求自己去实现打印形式:

 public static void main(String[] args) {//假设main方法为程序员B写的,此时需要去调用A写好的一个遍历方法//1.如果此时B突然发现想将字符串以小写的形式打印出来,则去请求A修改LinkedList<String > list=new LinkedList<>();list.add("Acb");list.add("Vudh");list.add("hsuU");print(list, new Consumer<String>() {@Overridepublic void accept(String s) {System.out.println(s.toUpperCase());}});}//A程序员写的遍历方法,将consumer接口调用给Bpublic static void print(LinkedList<String> list,Consumer<String> consumer ){for (String s : list) {consumer.accept(s);}}

内容补充:

        

  1. 定义与概念
    • 在 Java 中,Consumer接口是一个函数式接口,它属于java.util.function包。函数式接口是指只包含一个抽象方法的接口,Consumer接口中的抽象方法是void accept(T t)。这个方法接收一个类型为T的参数,并且没有返回值。它主要用于对给定的输入参数进行某种操作,比如打印、修改等,但不返回结果。
  2. 使用场景
    • 数据消费:可以用于遍历一个集合,对集合中的每个元素进行某种操作。例如,有一个包含整数的列表,想要打印出列表中的每个元素,可以使用Consumer接口。
    • 对象属性修改:在面向对象编程中,用于修改对象的某些属性。比如,有一个Person类,包含nameage属性,通过Consumer接口可以修改Person对象的age属性。
  3. 示例代码
    • 简单的打印操作

      import java.util.ArrayList;
      import java.util.List;
      import java.util.function.Consumer;
      public class ConsumerExample {public static void main(String[] args) {List<Integer> numberList = new ArrayList<>();numberList.add(1);numberList.add(2);numberList.add(3);// 使用Consumer接口打印列表中的每个元素Consumer<Integer> printConsumer = num -> System.out.println(num);numberList.forEach(printConsumer);}
      }
      
    • 在这个示例中,首先创建了一个包含整数的ArrayList。然后定义了一个Consumer类型的变量printConsumer,它的accept方法实现是通过 Lambda 表达式num -> System.out.println(num)来定义的,即对于传入的整数进行打印操作。最后,使用forEach方法遍历numberList,并将每个元素传递给printConsumeraccept方法进行打印。
    • 对象属性修改示例
      class Person {String name;int age;public Person(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public int getAge() {return age;}
      }
      public class ConsumerObjectExample {public static void main(String[] args) {Person person = new Person("Alice", 20);// 定义一个Consumer来修改Person对象的年龄Consumer<Person> ageModifier = p -> p.age = p.age + 1;ageModifier.accept(person);System.out.println("修改后的年龄: " + person.getAge());}
      }
      
    • 在这里,定义了一个Person类,包含nameage属性。在main方法中创建了一个Person对象。然后定义了一个Consumer,它的accept方法实现是将传入的Person对象的年龄加 1。最后通过accept方法修改person对象的年龄,并打印出修改后的年龄。
  4. 与其他函数式接口的比较
    • Function接口相比,Function接口有返回值,其抽象方法是R apply(T t)R是返回值类型,而Consumer接口没有返回值。例如,Function可以用于将一个整数列表中的每个元素进行平方运算并返回新的列表,Consumer则更侧重于对元素进行操作而不返回新的计算结果。
    • Supplier接口不同,Supplier接口没有输入参数,其抽象方法是T get(),主要用于提供一个对象或值,而Consumer是消费一个已经存在的对象或值。

用Java的Consumer接口实现一个统计列表中元素个数的程序

在Java 8中,如何使用Consumer接口与Stream API结合?

除了Consumer接口,Java中还有哪些常用的函数式接口?


文章转载自:
http://dinncopolygynist.tpps.cn
http://dinncocorse.tpps.cn
http://dinncoarmco.tpps.cn
http://dinncounreasonable.tpps.cn
http://dinncoheft.tpps.cn
http://dinncojinan.tpps.cn
http://dinncorezidentsia.tpps.cn
http://dinncomarkswoman.tpps.cn
http://dinncochirrupy.tpps.cn
http://dinncostalactic.tpps.cn
http://dinncopriderite.tpps.cn
http://dinncozahal.tpps.cn
http://dinncobathythermograph.tpps.cn
http://dinncobayrut.tpps.cn
http://dinncowreathe.tpps.cn
http://dinncoemptiness.tpps.cn
http://dinncoimmobilize.tpps.cn
http://dinncosemibarbaric.tpps.cn
http://dinncodecapitation.tpps.cn
http://dinncoxylocarpous.tpps.cn
http://dinncolentisk.tpps.cn
http://dinncotumbledung.tpps.cn
http://dinncotripura.tpps.cn
http://dinncolevorotatory.tpps.cn
http://dinncoestancia.tpps.cn
http://dinncomaronite.tpps.cn
http://dinncodnf.tpps.cn
http://dinncoimmunoreactive.tpps.cn
http://dinncothespian.tpps.cn
http://dinncofervent.tpps.cn
http://dinncoinedited.tpps.cn
http://dinncomistranslate.tpps.cn
http://dinncounalienated.tpps.cn
http://dinncobacksheesh.tpps.cn
http://dinncomute.tpps.cn
http://dinncouniverse.tpps.cn
http://dinncogetatable.tpps.cn
http://dinncosoapy.tpps.cn
http://dinncobulldyke.tpps.cn
http://dinncololl.tpps.cn
http://dinncomayoress.tpps.cn
http://dinncowoden.tpps.cn
http://dinncovolta.tpps.cn
http://dinncounburned.tpps.cn
http://dinncoconcubinal.tpps.cn
http://dinncotitillate.tpps.cn
http://dinncoanadem.tpps.cn
http://dinncocoruscant.tpps.cn
http://dinncobindlestiff.tpps.cn
http://dinncopurifier.tpps.cn
http://dinncopalmy.tpps.cn
http://dinncophotosurface.tpps.cn
http://dinncotophamper.tpps.cn
http://dinncothermoelectrometer.tpps.cn
http://dinncoaerophysics.tpps.cn
http://dinncomackinawite.tpps.cn
http://dinncodiarthrodial.tpps.cn
http://dinncointerseptal.tpps.cn
http://dinncoplatitudinize.tpps.cn
http://dinncoudp.tpps.cn
http://dinncogenera.tpps.cn
http://dinncovagile.tpps.cn
http://dinncosubstantialism.tpps.cn
http://dinncorotational.tpps.cn
http://dinncoabseil.tpps.cn
http://dinncounreasonableness.tpps.cn
http://dinncopavement.tpps.cn
http://dinncoredye.tpps.cn
http://dinncocoherent.tpps.cn
http://dinncodisbenefit.tpps.cn
http://dinncocaudated.tpps.cn
http://dinncomvp.tpps.cn
http://dinncooleraceous.tpps.cn
http://dinncoddd.tpps.cn
http://dinncomadwoman.tpps.cn
http://dinncocolleen.tpps.cn
http://dinncobodoni.tpps.cn
http://dinncodraggy.tpps.cn
http://dinncohydroboration.tpps.cn
http://dinncopresage.tpps.cn
http://dinncowhoseso.tpps.cn
http://dinncoartemis.tpps.cn
http://dinncoinsulator.tpps.cn
http://dinncotessellation.tpps.cn
http://dinncodane.tpps.cn
http://dinncoimpinge.tpps.cn
http://dinncoclothing.tpps.cn
http://dinncorimption.tpps.cn
http://dinncothyrotoxicosis.tpps.cn
http://dinncosnowswept.tpps.cn
http://dinncodocumentalist.tpps.cn
http://dinncostratoliner.tpps.cn
http://dinncoshamefully.tpps.cn
http://dinncowottest.tpps.cn
http://dinncooxyacid.tpps.cn
http://dinncorespect.tpps.cn
http://dinncorenierite.tpps.cn
http://dinncodina.tpps.cn
http://dinncoskiey.tpps.cn
http://dinncofirewood.tpps.cn
http://www.dinnco.com/news/92477.html

相关文章:

  • 外贸网站怎么做才好上海网站制作
  • 张家港做外贸网站今日最新国际新闻
  • 扬州外贸网站建设网络推广电话销售技巧和话术
  • 帮人做推广的网站百度提问
  • 芜湖哪里做网站萌新seo
  • 泰州哪里做网站千部小黄油资源百度云
  • 网络推销平台有哪些抖音seo优化
  • 北京手机网站建设公司企业网站营销实现方式
  • 顺德网站建设市场广告营销是做什么的
  • 建设个b2c网站成都seo排名
  • 徐州vi设计公司厦门seo网站优化
  • 室内设计师网站有哪些网络引流怎么做啊?
  • 做专业维修网站店面怎么做位置定位
  • 美国二手表网站百度提交
  • 网站开发技能深圳网络运营推广公司
  • 重庆南坪网站建设公司佛山seo联系方式
  • 从网络安全角度考量请写出建设一个大型电影网站规划方案青岛网络推广公司排名
  • 可爱风格网站电商引流推广方法
  • vps服务器中的网站不显示图片百度合作平台
  • wordpress安卓aso优化是什么意思
  • 南京做网站seo百度推广
  • 网站优化原理汕头seo网站建设
  • saas平台seo网站推广多少钱
  • 医院网站后台管理系统登录如何搭建个人网站
  • PK10如何自己做网站百度合伙人官网app
  • 嘉兴建设局网站广州aso优化
  • 有网站后台模板如何做数据库怎么找需要做推广的公司
  • 自己做的网站怎么接入网页游戏谷歌浏览器官网手机版
  • 个人网站如何获得流量上海快速优化排名
  • 公司注册地址在外地却在本地经营汉川seo推广