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

asp.net 网站开发教程两个wordpress之间同步

asp.net 网站开发教程,两个wordpress之间同步,南京it外包公司,哔哩哔哩视频免费视频大全知识模块#xff1a; 一.方法引用a.方法概述b.方法引用格式 二.Stream流1.Stream流概述2.Stream流操作步骤一.方法引用a.方法概述/*方法引用概述#xff1a;当我们使用已有类中的方法作为Lambda表达式对应的接口中的抽象方法实现我们可以用方法引用来简化Lambda表达式*/impor…知识模块 一.方法引用a.方法概述b.方法引用格式 二.Stream流1.Stream流概述2.Stream流操作步骤一.方法引用a.方法概述/*方法引用概述当我们使用已有类中的方法作为Lambda表达式对应的接口中的抽象方法实现我们可以用方法引用来简化Lambda表达式*/import org.junit.Test;import java.util.function.Consumer;/*方法引用概述当我们使用已有类中的方法作为Lambda表达式对应的接口中的抽象方法实现我们可以用方法引用来简化Lambda表达式*/ public class MethodRef01 {Testpublic void test01() {ConsumerString c str - System.out.println(str);c.accept(abc);System.out.println(System.out);//java.io.PrintStreamf5f2bb7}Testpublic void test02() {//ConsumerString c str - System.out.println(str);ConsumerStringcSystem.out::println; //System.out代表了我们要引用的类//::后面的println代表我们引用的方法c.accept(abc);}} /*class MethodRefDemo$$Lambda$1 implements ConsumersTRING{public void accept(String str){System.out.println(str);//我们使用是PrintStream类中的println(String str)方法//作为str-System.out.println(str)对应的ConsumerString//中accept(String str)的实现}}*/b.方法引用格式方法引用使用的前提(适用于12)引用的方法和Lambda表达式对应接口中的抽象方法中的形参类型保持一致1.成员方法引用a.引用非静态成员方法/*非静态成员引用对象名::方法名*/import java.util.Objects;public class Person {private String name;public Person(String name) {this.name name;}public String getName() {return name;}public void setName(String name) {this.name name;}Overridepublic String toString() {return Person{ name name \ };}Overridepublic boolean equals(Object o) {if (this o) return true;if (!(o instanceof Person person)) return false;return name.equals(person.name);}Overridepublic int hashCode() {return Objects.hash(name);} }import org.junit.Test;import java.util.function.Consumer; import java.util.function.Supplier;/*方法引用使用的前提引用的方法和Lambda表达式对应接口中的抽象方法中的形参类型保持一致非静态成员引用对象名::方法名*/ public class MethodRefDemo02 {Person p new Person(老王);Testpublic void test01() {//SupplierString s()-p.getName();SupplierString s p::getName;System.out.println(s.get());}Testpublic void test02() {//ConsumerString c name - p.setName(name);ConsumerStringcp::setName;c.accept(老李);System.out.println(p);}Testpublic void test03() {String str abc;//SupplierInteger s () - str.length();SupplierInteger s str::length;System.out.println(s.get());}Testpublic void test04() {String str abc;//SupplierCharacter s () - str.charAt(1);/* SupplierCharactersstr::charAt; //一个有参一个无参不能简化System.out.println(s.get());*/} }b.引用静态成员方法/*静态方法引用类名::静态方法名Arrays,CollectionsArrays类中static String toString(int[] a)返回指定数组内容的字符串表示形式。Collections类public static T extends Comparable? super T void sort(ListT list)根据元素的自然顺序 对指定列表按升序进行排序*/import org.junit.Test;import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Consumer; import java.util.function.Function;/*静态方法引用类名::静态方法名Arrays,CollectionsArrays类中static String toString(int[] a)返回指定数组内容的字符串表示形式。Collections类public static T extends Comparable? super T void sort(ListT list)根据元素的自然顺序 对指定列表按升序进行排序*/ public class MethodRefDemo03 {Testpublic void test01() {int[] arr {3, 7, 9};//Functionint[], String f array - Arrays.toString(array);Functionint[],StringfArrays::toString;System.out.println(f.apply(arr));}Testpublic void test02() {ListInteger integers Arrays.asList(1, 7, 12, 5, 23);//ConsumerListInteger c list - Collections.sort(list);ConsumerListInteger c Collections::sort;c.accept(integers);System.out.println(integers);} }2.构造方法引用/*构造方法引用格式类名::new*/3.数组对象引用数组对象引用格式类型[]::new import org.junit.Test;import java.util.function.Function;/*构造方法引用格式类名::new数组对象引用格式类型[]::new*/ public class MethodRefDemo04 {Testpublic void test01() {//创建一个Person类的对象获取这个对象//FunctionString, Person f name - new Person(name);FunctionString, Person f Person::new;System.out.println(f.apply(三丰));}Testpublic void test02() {//创建一个指定长度的数组返回这个数组对象//FunctionInteger, int[] f n - new int[n];FunctionInteger, int[] fint[]::new;System.out.println(f.apply(4).length);} }4.特殊的非静态方法/*特殊的非静态方法的引用格式类名::非静态方法名***1.不再适用于放啊引用的前提条件2.当Lambda表达式第一个参数作为实例(非静态)方法的调用者第二个参数作为实例对象的参数可以受用 类名::非静态方法名3.当Lambda表达式的参数作为一个空参实例方法的调用者时候也可使用 类名::非静态方法名*/import org.junit.Test;import java.util.function.BiPredicate; import java.util.function.Function;/*特殊的非静态方法的引用格式类名::非静态方法名1.不再适用于放啊引用的前提条件2.当Lambda表达式第一个参数作为实例(非静态)方法的调用者第二个参数作为实例对象的参数可以受用 类名::非静态方法名3.当Lambda表达式的参数作为一个空参实例方法的调用者时候也可使用 类名::非静态方法名*/ public class MethodRefDemo05 {Testpublic void test01() {Person p1 new Person(老王);Person p2 new Person(老李);//BiPredicatePerson, Person bp (person1, person2) - person1.equals(person2);BiPredicatePerson, Person bp Person::equals;System.out.println(bp.test(p1, p2));}Testpublic void test02() {Person p1 new Person(老王);//FunctionPerson, String f person - person.getName();FunctionPerson, String f Person::getName;System.out.println(f.apply(p1));} }二.Stream流1.Stream流概述Strean流的出现是为了增强集合和数组的操作Stream流更专注于数据的转换过滤获取等一系列操作同时Stream流提高了操作集合和数组的小笼包简化了代码import org.junit.Test;import java.util.ArrayList; import java.util.Arrays; import java.util.List;/*Stream流的概述统计后缀名为.txt文件名称的个数*/ public class StreamDemo01 {Testpublic void test01() {ArrayListString al new ArrayListString();al.add(1.txt);al.add(2.txt);al.add(3.pdf);al.add(4.docx);int count0;for (String s : al) {if (s.endsWith(.txt)) {count;}}System.out.println(count);}Testpublic void test02() {ListString list Arrays.asList(1.txt, 2.txt, 3.pdf, 4.docx);/*long count list.stream().filter(str - str.endsWith(.txt)).count();System.out.println(count);*/System.out.println(list.stream().filter(str - str.endsWith(.txt)).count());} }2.Stream流操作步骤1.根据数据源获取一个Stream对象/*集合或数组流对象的获取集合Collection体系:都是通过Stream()方法来获取一个流对象ListSetMap体系 需要转换到Collection体系的集合才能调用stream()方法获取一个流对象HashMap数组static T StreamT of(T... values)返回一个元素为指定值的顺序排列的流。*/import org.junit.Test;import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.stream.Stream;/*集合或数组流对象的获取集合Collection体系:都是通过Stream()方法来获取一个流对象ListSetMap体系 需要转换到Collection体系的集合才能调用stream()方法获取一个流对象HashMap数组static T StreamT of(T... values)返回一个元素为指定值的顺序排列的流。*/ public class StreamDemo02 {Testpublic void test01() {StreamStream stream1 new ArrayListStream().stream();//Stream流上的泛型和集合中元素的类型相对应//当我们通过集合对象来调用stream()方法相当于//将集合中的元素添加到Stream流中等待操作StreamInteger stream2 new HashSetInteger().stream();//Stream流上的泛型和集合中元素的类型相对应}Testpublic void test02() {new HashMapInteger,Stream().keySet().stream();//需要将Map转换成Collection体系的集合就可以使用stream()方法获取流对象//将一个个key添加到stream中new HashMapInteger,String().entrySet().stream();//将一个entry对象{keyvalue}添加到stream流中}Testpublic void test03() {int[] arr {1, 3, 9};Streamint[] stream1 Stream.of(arr);//如果通过基本类型数组获取一个流对象此时六种只有一个元素这个数组对象Integer[] arr2 {1, 3, 9};StreamInteger stream2 Stream.of(arr2);//我们通过基本类型对应的包装类的引用类型数组获取流对象此时相当于将数组中的元素添加到流中StreamString stream3 Stream.of(abc, def, ghk);//通过一串数据获取流对象StreamInteger stream4 Stream.of(3, 5, 7);} } 2.通过Stream对象可以进行0次或多次中间操作/*中间操作过滤操作filter传入一个Predicate根据Predicate中的条件对流中的元素做一个筛选满足条件保留不满足的剔除排序操作sorted可以根据指定的规则将流中的元素从小到大排序去重操作distinct去除流中重复的元素截取操作limit根据传入的值来决定截取流总元素的个数skip 根据传入的值决定跳过流中的元素个数映射操作map讲义中数据根据指定操作映射成另一种数据mapToIntmapToDoublemapToLong*/public class Student {//学生姓名private String name;//语文成绩private double chineseScore;//数学成绩private double mathScore;public Student(String name, double chineseScore, double mathScore) {this.name name;this.chineseScore chineseScore;this.mathScore mathScore;}public String getName() {return name;}public void setName(String name) {this.name name;}public double getChineseScore() {return chineseScore;}public void setChineseScore(double chineseScore) {this.chineseScore chineseScore;}public double getMathScore() {return mathScore;}public void setMathScore(double mathScore) {this.mathScore mathScore;}Overridepublic String toString() {return Student{ name name \ , chineseScore chineseScore , mathScore mathScore };} }/*中间操作过滤操作filter传入一个Predicate根据Predicate中的条件对流中的元素做一个筛选满足条件保留不满足的剔除排序操作sorted可以根据指定的规则将流中的元素从小到大排序去重操作distinct去除流中重复的元素截取操作limit根据传入的值来决定截取流总元素的个数skip 根据传入的值决定跳过流中的元素个数映射操作map讲义中数据根据指定操作映射成另一种数据mapToIntmapToDoublemapToLong班级中有5个人姓名,语文成绩,数学成绩分别如下李雷, 70, 90韩梅梅, 30, 100李宁, 85, 80王松,70,60张家界,90,73需求:1.打印语文成绩80的学生信息2.打印数学成绩前三名的学生信息3.打印数学成绩倒数第一和倒数第二的学生信息4.获取全班数学的平均成绩5.获取全班语文成绩(不包含重复成绩)6.将语文成绩或数学成绩在[80,90]之间的学生的姓名收集到一个集合中*/import org.junit.Before; import org.junit.Test;import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors;public class StreamDemo04 {//Before会在所有的Test注解之前执行ListStudent students;Beforepublic void init() {//初始化数据源students Arrays.asList(new Student(李雷, 70, 90),new Student(韩梅梅, 30, 100),new Student(李宁, 85, 80),new Student(王松, 70, 60),new Student(张家界, 90, 73));}Testpublic void test02() {//1.打印语文成绩80的学生信息students.stream().filter(stu - stu.getChineseScore() 80).forEach(System.out::println);}Testpublic void test03() {//2.打印数学成绩前三名的学生信息/*a.首先需要对学生的成绩从大到小排序b.获取前三名的信息*/students.stream().sorted((stu1,stu2)-(int)(stu2.getMathScore()-stu1.getMathScore())).limit(3)//截取流中的前三个元素.forEach(System.out::println);}Testpublic void test04() {// 3.打印数学成绩倒数第一和倒数第二的学生信息/*a.首先需要对学生的数学成绩从大到小排序b.获取倒数第一和倒数第二*/students.stream().sorted((stu1, stu2) - (int) (stu2.getMathScore() - stu1.getMathScore())).skip(students.size() - 2).forEach(System.out::println);}Testpublic void test05() {//4.获取全班数学的平均成绩//将流中的以恶搞个学生对象映射成每个学生对应的数学成绩double avgScore students.stream().mapToDouble(stu - stu.getMathScore()).average().getAsDouble();System.out.println(avgScore);}Testpublic void test06() {// 5.获取全班语文成绩(不包含重复成绩)// 需要使用mapToDouble//students.stream().mapToDouble(stu-stu.getChineseScore()).distinct().forEach(System.out::println);//students.stream().map(stu-stu.getChineseScore()).distinct().forEach(System.out::println);students.stream().map(Student::getChineseScore).distinct().forEach(System.out::println);}Testpublic void test07() {// 6.将语文成绩或数学成绩在[80,90]之间的学生的姓名收集到一个集合中//a.语文成绩在[80,90]之间的学生(Predicate) 或者 数学成绩在[80,90]之间(Predicate)//b.将过滤后的一个个学生对象映射成一个个学生姓名//c.将过滤和映射中间操作后的数据收集到以恶搞集合中PredicateStudentp1stu-stu.getChineseScore()80stu.getChineseScore()90;PredicateStudentp2stu-stu.getMathScore()80stu.getMathScore()90;ListString names students.stream().filter(p1.or(p2)).map(Student::getName).collect(Collectors.toList());System.out.println(names);} }3.进行一次最终操作获取最终结果/*Stream流的最终操作1.迭代forEach:逐个消费流中的元素2.统计count:统计流中元素的个数max :按照一定比较规则(Comparator接口实现规则)来获取流中最大元素min :按照一定比较规则(Comparator接口实现规则)来获取流中最小元素3.查找findFirst4.匹配allMatch只有流中所有的元素都满足Predicate(条件)allMatch方法才返回true否则返回falseanyMatch只有流中有一个元素满足Predicate(条件)anyMatch方法才返回true否则返回falsenoneMatch只有流中所有的元素都不满足Predicate(条件)noneMatch方法才返回true否则返回false5.收集collect我们可以将最终操作结果收集到一个集合(List,Set,Map)我们主要通过Collections.toList(),Collections.toSet(),Collections.toMap(),将最终操作结果收集到不同集合中中间操作sorted*/ import org.junit.Test;import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream;/*Stream流的最终操作1.迭代forEach:逐个消费流中的元素2.统计count:统计流中元素的个数max :按照一定比较规则(Comparator接口实现规则)来获取流中最大元素min :按照一定比较规则(Comparator接口实现规则)来获取流中最小元素3.查找findFirst4.匹配allMatch只有流中所有的元素都满足Predicate(条件)allMatch方法才返回true否则返回falseanyMatch只有流中有一个元素满足Predicate(条件)anyMatch方法才返回true否则返回falsenoneMatch只有流中所有的元素都不满足Predicate(条件)noneMatch方法才返回true否则返回false5.收集collect我们可以将最终操作结果收集到一个集合(List,Set,Map)我们主要通过Collections.toList(),Collections.toSet(),Collections.toMap(),将最终操作结果收集到不同集合中中间操作sorted*/ public class StreamDemo03 {ListString list Arrays.asList(zhangsan, lisi, laowang);Testpublic void test01() {//list.stream().forEach(str- System.out.println(str));list.stream().forEach(System.out::println);}Testpublic void test02() {long count list.stream().count();System.out.println(count);}Testpublic void test03() {list.stream().sorted().forEach(System.out::println);//字符串的默认排序方式是字典顺序System.out.println(------------);/*Comparator接口的int compare(T o1, T o2);如果compare方法返回一个正数默认为o1o2如果compare方法返回一个负数默认为o1o2如果compare方法返回0默认为o1o2sorted方法默认按照元素从小到大排序比较流程str1lisistr2zhangsanstr1.length() - str2.length()0 lisizhangsan第二种情况str2.length() - str1.length() 0 lisizhangsanstr1laowangstr2zhangsanstr1.lemgth() - str2.length() laowangzhangsan第二种情况 str2.length() - str1.length()0 laowangzhangsanstr1laowangstr2lisistr1.length() - str2.length() laiwanglisi第二种情况 str2.length() - str1.length()0 laowangkisi最终结果 listlaowangzhangsan第二种情况最终结果 zhangsanlaowanglisi*/list.stream().sorted((str1, str2) - str1.length() - str2.length()).forEach(System.out::println);System.out.println(-------------------);list.stream().sorted((str1, str2) - str2.length() - str1.length()).forEach(System.out::println);}//ListString list Arrays.asList(zhangsan, lisi, laowang);Testpublic void test04() {//获取最大长度的字符串System.out.println(list.stream().max((str1, str2) - str1.length() - str2.length()).get());//获取最小长度字符串System.out.println(list.stream().min((str1, str2) - str1.length() - str2.length()).get());}Testpublic void test05() {System.out.println(list.stream().findFirst().get());}Testpublic void test06() {System.out.println(list.stream().allMatch(str - str.length() 4));//falseSystem.out.println(list.stream().anyMatch(str - str.length() 4));//trueSystem.out.println(list.stream().noneMatch(str - str.length() 4));//true}Testpublic void test07() {StreamString stream list.stream();ListString l stream.collect(Collectors.toList());//将流中的数据收集到List集合中System.out.println(l.getClass());System.out.println(l.size());}Testpublic void test08() {SetString set list.stream().collect(Collectors.toSet());System.out.println(set);}Testpublic void test09() {//将字符串的长度作为ley字符串的值作为value去构造一个mapMapInteger, String map list.stream().collect(Collectors.toMap(str - str.length(), str - str));System.out.println(map);} }
http://www.zqtcl.cn/news/66591/

相关文章:

  • 阜城网站建设代理东莞常平核酸检测点
  • 网站设计制作工作室怎么自己做导航网站
  • 网站制造外包做网站价格
  • 网站备案模板如何查看网站的关键词
  • 伊犁建设网站公司做设计什么网站平台好点做私活
  • 湖南建设集团网站廉江网站建设公司
  • 免费网页制作的网站qq怎么做放资源的网站
  • 广东省住房和建设局网站电商购物网站建设
  • 返回链接 网站惩罚检查 错误检查做网站公司经营范围
  • 天津市区县档案部门网站建设指导意见长沙logo设计公司哪家好些
  • cad做兼职区哪个网站有关网站建设的说说
  • 漳州seo建站资阳建设局网站
  • 网站制作功能多少钱粒子特效网站
  • 网站多服务器建设的推网站模板
  • 如何与知名网站做友情链接微信下载官方正版
  • asp.net 网站提速wordpress 开源主题
  • 网站名称怎么填写站长工具seo
  • 腾讯云 网站备案菏泽建设公司网站
  • 开发公司对设计单位奖惩快速排名软件seo系统
  • 厦门国外网站建设公司网站开发和系统开发的区别
  • 网站网页设计案例高埗网站建设公司
  • 建立网站的流程的合理顺序企业内部信息网站如何建设
  • 网站建设多少带宽wordpress 用户登录
  • 电商网站开发网站开发的费用
  • 南宁市住房城乡建设厅网站wordpress语言更改
  • 富阳区住房与建设局网站网站背景全屏
  • 张家港建设局网站淘宝 客要推广网站怎么做
  • 长春网站制作优势吉网传媒西部数码域名注册
  • 论坛网站模板公众号开发工具
  • 设计网站意味着什么一个后台可以做几个网站