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

云南网站定制开发dede网站演示

云南网站定制开发,dede网站演示,东莞哪里有网站建设厂家,做网站的上海公司有哪些Stream 也叫Stream流#xff0c;是Jdk8开始新增的一套API (java.util.stream.*)#xff0c;可以用于操作集合或者数组的数据。 Stream流大量的结合了Lambda的语法风格来编程#xff0c;提供了一种更加强大#xff0c;更加简单的方式操作 public class Demo1 {public stati…Stream 也叫Stream流是Jdk8开始新增的一套API (java.util.stream.*)可以用于操作集合或者数组的数据。 Stream流大量的结合了Lambda的语法风格来编程提供了一种更加强大更加简单的方式操作 public class Demo1 {public static void main(String[] args) {ListString list new ArrayList();list.add(张无忌);list.add(周芷若);list.add(赵敏);list.add(张强);list.add(张三丰);//需求:把集合中所有以张开头且是3个字的元素存储到一个新的集合。//实现2: 使用Stream流方式实现ListString list1 list.stream().filter(name - name.startsWith(张) ).filter(name - name.length() 3).collect(Collectors.toList());System.out.println(list1);} } Stream流的使用步骤  1.                                       2.                                              3. 如何获取Stream流  如何获取Stream流:Collection集合:单列集合都支持一个stream()方法,它可以直接获取集合的Stream流数组:Arrays.stream(数组)零散数据:Stream.of(T... values)Map双列集合并没有提供直接获取Stream流的方法,他需要间接获取public class Demo2 {public static void main(String[] args) {//玄奘, 悟空, 悟能, 悟净ListString list List.of(玄奘, 悟空, 悟能, 悟净);//Collection集合: 单列集合都支持一个stream()方法,它可以直接获取集合的Stream流list.stream().forEach(System.out::println);//数组:Arrays.stream(数组)System.out.println(-------------------------------------);String[] arr {玄奘, 悟空, 悟能, 悟净};Arrays.stream(arr).forEach(System.out::println);//零散数据:Stream.of(T... values)System.out.println(-------------------------------------);Stream.of(玄奘, 悟空, 悟能, 悟净).forEach(System.out::println);//Map:双列集合并没有提供直接获取Stream流的方法,他需要间接获取System.out.println(-------------------------------------);MapString,String map new HashMap();map.put(001,玄奘);map.put(002,悟空);map.put(003,悟能);map.put(004,悟净);//返回一个Set集合map.keySet().stream().forEach(System.out::println);map.values().stream().forEach(System.out::println);System.out.println(-------------------------------------);//这是一个整体EntrySetkeyvalue - emap.entrySet().stream().forEach(e - System.out.println(e.getValue() e.getKey()));} } Stream流常见中间方法  public class Demo3 {public static void main(String[] args) {ListInteger list List.of(61, 57, 66, 77, 88, 44, 100, 89, 97, 47, 70);//需求1: 找出所有及格的分数,并打印System.out.println();list.stream().filter(e - e 60).forEach(System.out::println);//需求2: 找出所有及格的分数, 正序排列, 打印输出System.out.println();list.stream().filter(e - e 60).sorted((o1, o2) - o1 - o2).forEach(System.out::println);//需求3: 找出所有及格的分数, 倒序排列, 打印输出System.out.println();list.stream().filter(e - e 60).sorted((o1, o2) - o2 - o1).forEach(System.out::println);//需求4: 找出所有及格的分数, 倒序排列, 取前3名, 打印输出System.out.println();list.stream().filter(e - e 60).sorted((o1, o2) - o2 - o1).limit(3).forEach(System.out::println);//需求5: 找出所有及格的分数, 倒序排列, 取前4-6名, 打印输出System.out.println();list.stream().filter(e - e 60).sorted((o1, o2) - o2 - o1).skip(3).limit(3).forEach(System.out::println);//需求6: 找出所有及格的分数, 倒序排列, 取前4-6名, 将每个人的分数加10分, 打印输出System.out.println();list.stream().filter(e - e 60).sorted((o1, o2) - o2 - o1).skip(3).limit(3).map(e - e 10).forEach(System.out::println);//需求7: 将下面两个集合中的元素进行合并去重System.out.println();ListString list1 List.of(1,2,3,4);ListString list2 List.of(1,5,7,4);Stream.concat(list1.stream(),list2.stream()).distinct().forEach(System.out::println);} } Stream流常见终结方法 调用完成后不会返回新Stream了没法继续使用流了。  public class Demo4 {public static void main(String[] args) {ListStudent list List.of(new Student(玄奘, 60, 165.5),new Student(悟空, 50, 175.5),new Student(悟能, 55, 145.5),new Student(悟净, 40, 185.5));//1. 打印出集合中所有元素list.stream().forEach(System.out::println);//2. 统计出身高不足170的人数StreamStudent stream list.stream().filter(e - e.getHeight() 170);long count stream.count();System.out.println(count);//3. 请找出年龄最大的对象, 并输出(了解)Student student list.stream().max((o1, o2) - o1.getAge() - o2.getAge()).get();System.out.println(student);//4. 请找出身高最低的对象, 并输出(了解)Student student2 list.stream().min((o1, o2) - Double.compare(o1.getHeight(),o2.getHeight())).get();System.out.println(student2);} }class Student {private String name;private int age;private double height;public Student() {}public Student(String name, int age, double height) {this.name name;this.age age;this.height height;}public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}public double getHeight() {return height;}public void setHeight(double height) {this.height height;}Overridepublic String toString() {return Student{ name name \ , age age , height height };} } Stream流转数组/集合  public class Demo5 {public static void main(String[] args) {ListTeacher list List.of(new Teacher(玄奘, 60, 165.5),new Teacher(悟空, 50, 175.5),new Teacher(悟空, 50, 175.5),new Teacher(悟能, 55, 145.5),new Teacher(悟净, 40, 185.5));//1. 请找出身高超过170的教师, 并放到一个新数组中Object[] objects list.stream().filter(e - e.getHeight() 170).toArray();System.out.println(Arrays.toString(objects));Teacher[] teacher list.stream().filter(e - e.getHeight() 170)//len代表元素中的个数.toArray(len - new Teacher[len]);System.out.println(Arrays.toString(teacher));//2. 请找出身高超过170的教师, 并放到一个新List集合中ListTeacher list1 list.stream().filter(e - e.getHeight() 170).collect(Collectors.toList());System.out.println(list1);//3. 请找出身高超过170的教师, 并放到一个新Set集合中SetTeacher list2 list.stream().filter(e - e.getHeight() 170).collect(Collectors.toSet());System.out.println(list2);//4. 请找出所有的教师的姓名和身高, 放到一个新Map集合中MapString,Double map list.stream().distinct().collect(Collectors.toMap(e - e.getName(), e- e.getHeight()));System.out.println(map);} }class Teacher {private String name;private int age;private double height;public Teacher() {}public Teacher(String name, int age, double height) {this.name name;this.age age;this.height height;}public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}public double getHeight() {return height;}public void setHeight(double height) {this.height height;}Overridepublic boolean equals(Object o) {if (this o) return true;if (o null || getClass() ! o.getClass()) return false;Teacher teacher (Teacher) o;return age teacher.age Double.compare(teacher.height, height) 0 Objects.equals(name, teacher.name);}Overridepublic int hashCode() {return Objects.hash(name, age, height);}Overridepublic String toString() {return Teacher{ name name \ , age age , height height };} }Map集合 1.Map集合称为双列集合一次需要存一对数据做为一个元素, 格式{key1value1 ,        key2value2 , key3value3 , ...} 2.Map集合的所有键是不允许重复的但值可以重复键和值是一一对应的每一个键只能找到自己对应的值 Map集合体系 Map集合的实现类有哪些各自的特点是  1.HashMap: 无序不重复 2.LinkedHashMap: 有序不重复 3.TreeMap排序不重复  Map接口常用方法 Map集合三种遍历方式  public class Demo2 {public static void main(String[] args) {//1. 创建mapHashMapString, String map new HashMap();map.put(001, 玄奘);map.put(002, 悟空);map.put(003, 悟能);map.put(004, 悟净);//2. 各种方式进行遍历test1(map);System.out.println();test2(map);System.out.println();test3(map);}//遍历方式1: 先获取Map集合全部的键再通过遍历键来找值private static void test1(HashMapString, String map) {SetString set map.keySet();for (String s : set) {System.out.println(s map.get(s));}}//遍历方式2: 将map中的所有键值对放入一个set集合中, 然后遍历set集合拿到每个键值对, 再取里面的键值private static void test2(HashMapString, String map) {SetMap.EntryString, String entries map.entrySet();for (Map.EntryString, String entry : entries) {System.out.println(entry.getKey() entry.getValue());}}//遍历方式3: Lambda, 使用foreach(BiConsumer bc)private static void test3(HashMapString, String map) {map.forEach((k,v) - System.out.println(kv));} } Map集合案例  现有字符串数组如下:String[] bookArr {《红楼梦》-曹雪芹,《西游记》-吴承恩,《三国演义》-罗贯中,《水浒传》-施耐庵}; 需求:请将字符串中的书名提取为Map集合的键将作者提取为Map集合的值并使用三种不同方式遍历Map集合打印键值对元素内容 public class Demo3 {public static void main(String[] args) {MapString,String map new HashMap();String[] bookArr {《红楼梦》-曹雪芹,《西游记》-吴承恩,《三国演义》-罗贯中,《水浒传》-施耐庵};for (String book : bookArr) {String[] split book.split(-);map.put(split[0],split[1] );}System.out.println(map);SetString set map.keySet();for (String key : set) {System.out.println(key map.get(key));}System.out.println(----------------------------);SetMap.EntryString, String entries map.entrySet();for (Map.EntryString, String entry : entries) {System.out.println(entry.getKey()entry.getValue());}System.out.println(----------------------------);map.forEach((key , value) - System.out.println(keyvalue));} } HashMap底层原理 和HashSet一样 :Day06List接口Set接口树-CSDN博客https://blog.csdn.net/m0_60388241/article/details/133930070?spm1001.2014.3001.5501 LinkedHashMap 底层数据结构依然是基于哈希表实现的只是每个键值对元素又额外的多了一个双链表的机制记录元素顺序(保证有序)。  TreeMap  public class Demo6 {private String put;public static void main(String[] args) {//创建集合MapTeacher, String map new TreeMap((o1, o2) - o1.getAge() - o2.getAge());map.put(new Teacher(张三, 21), 河北);map.put(new Teacher(李四, 20), 山东);map.put(new Teacher(王五, 19), 山西);map.put(new Teacher(赵六, 21), 河南);map.forEach((k, v) - {System.out.println(k ----- v);});} }class Teacher {private String name;private int age;public Teacher() {}public Teacher(String name, int age) {this.name name;this.age age;}public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}Overridepublic String toString() {return Teacher{ name name \ , age age };} } 集合的嵌套 集合嵌套要求在程序中记住如下省份和其对应的城市信息记录成功后要求可以查询出湖北省的城市信息。数据江苏省 南京市,扬州市,苏州市,无锡市,常州市湖北省 武汉市,孝感市,十堰市,宜昌市,鄂州市河北省 石家庄市,唐山市,邢台市,保定市,张家口市分析:定义一个Map集合键用表示省份名称值表示城市名称注意城市会有多个。 MapString,ListString根据“湖北省”这个键获取对应的值展示即可。public class Demo7 {public static void main(String[] args) {MapString, ListString map new HashMap();ListString list List.of(南京市,扬州市,苏州市,无锡市,常州市);ListString list2 List.of(石家庄市,唐山市,邢台市,保定市,张家口市);map.put(江苏省,list);map.put(河北省,list2);System.out.println(map);} } Collections 可变参数  可变参数就是一种特殊形参定义在方法、构造器的形参列表里格式是数据类型... 参数名称优点特点可以不传数据给它可以传一个或者同时传多个数据给它也可以传一个数组给它。好处常常用来灵活的接收数据。注意事项1. 可变参数在方法内部就是一个数组2. 一个形参列表中可变参数只能有一个3. 可变参数必须放在形参列表的最后面public class Demo {public static void main(String[] args) {sum(1546);}//计算2个整数的和//计算3个整数的和//计算4个整数的和//计算n个整数的和public static void sum(int... a){for (int i : a) {System.out.println(i);}} }Collections工具类 public class Demo {public static void main(String[] args) {ListInteger list new ArrayList();//static T boolean addAll(单列集合可变参数) 批量添加元素Collections.addAll(list,1,2,100,3,45);System.out.println(list);//static void shuffle(List集合) 打乱List集合元素顺序每次调用都会打乱Collections.shuffle(list);System.out.println(list);//static T void sort(List集合) List集合进行自然排序Collections.sort(list);System.out.println(list);//排自定义类对象需要指定排序规则ListStudent stuList new ArrayList();stuList.add(new Student(zhangsan, 18));stuList.add(new Student(wangwu, 22));stuList.add(new Student(zhaoliu, 21));stuList.add(new Student(lisi, 19));stuList.add(new Student(qianqi, 20));//staticT void sort(List集合比较器);List集合进行比较器排序Collections.sort(stuList,(o1, o2) - o1.getAge() - o2.getAge());System.out.println(stuList);} }class Student {private String name;private int age;public Student() {}public Student(String name, int age) {this.name name;this.age age;}public String getName() {return name;}public void setName(String name) {this.name name;}public int getAge() {return age;}public void setAge(int age) {this.age age;}Overridepublic String toString() {return Student{ name name \ , age age };} }
文章转载自:
http://www.morning.lrzst.cn.gov.cn.lrzst.cn
http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn
http://www.morning.jykzy.cn.gov.cn.jykzy.cn
http://www.morning.pzss.cn.gov.cn.pzss.cn
http://www.morning.jlschmy.com.gov.cn.jlschmy.com
http://www.morning.ndynz.cn.gov.cn.ndynz.cn
http://www.morning.syssdz.cn.gov.cn.syssdz.cn
http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn
http://www.morning.fnbtn.cn.gov.cn.fnbtn.cn
http://www.morning.nxcgp.cn.gov.cn.nxcgp.cn
http://www.morning.ranglue.com.gov.cn.ranglue.com
http://www.morning.lsnnq.cn.gov.cn.lsnnq.cn
http://www.morning.rfrxt.cn.gov.cn.rfrxt.cn
http://www.morning.yqsr.cn.gov.cn.yqsr.cn
http://www.morning.ykwgl.cn.gov.cn.ykwgl.cn
http://www.morning.mqlsf.cn.gov.cn.mqlsf.cn
http://www.morning.fqlxg.cn.gov.cn.fqlxg.cn
http://www.morning.ptzf.cn.gov.cn.ptzf.cn
http://www.morning.rhqr.cn.gov.cn.rhqr.cn
http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn
http://www.morning.sfqtf.cn.gov.cn.sfqtf.cn
http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn
http://www.morning.ryglh.cn.gov.cn.ryglh.cn
http://www.morning.plfy.cn.gov.cn.plfy.cn
http://www.morning.jwwfk.cn.gov.cn.jwwfk.cn
http://www.morning.wktbz.cn.gov.cn.wktbz.cn
http://www.morning.flfxb.cn.gov.cn.flfxb.cn
http://www.morning.snjpj.cn.gov.cn.snjpj.cn
http://www.morning.pqypt.cn.gov.cn.pqypt.cn
http://www.morning.nrydm.cn.gov.cn.nrydm.cn
http://www.morning.mzydm.cn.gov.cn.mzydm.cn
http://www.morning.kgkph.cn.gov.cn.kgkph.cn
http://www.morning.rdfq.cn.gov.cn.rdfq.cn
http://www.morning.btsls.cn.gov.cn.btsls.cn
http://www.morning.zfqdt.cn.gov.cn.zfqdt.cn
http://www.morning.nwljj.cn.gov.cn.nwljj.cn
http://www.morning.pbpcj.cn.gov.cn.pbpcj.cn
http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn
http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn
http://www.morning.bylzr.cn.gov.cn.bylzr.cn
http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn
http://www.morning.ssjry.cn.gov.cn.ssjry.cn
http://www.morning.psqs.cn.gov.cn.psqs.cn
http://www.morning.jwbnm.cn.gov.cn.jwbnm.cn
http://www.morning.ptwzy.cn.gov.cn.ptwzy.cn
http://www.morning.kpzbf.cn.gov.cn.kpzbf.cn
http://www.morning.bnqcm.cn.gov.cn.bnqcm.cn
http://www.morning.ttkns.cn.gov.cn.ttkns.cn
http://www.morning.vnuwdy.cn.gov.cn.vnuwdy.cn
http://www.morning.vvbsxm.cn.gov.cn.vvbsxm.cn
http://www.morning.jjtwh.cn.gov.cn.jjtwh.cn
http://www.morning.wqrdx.cn.gov.cn.wqrdx.cn
http://www.morning.jczjf.cn.gov.cn.jczjf.cn
http://www.morning.rbtny.cn.gov.cn.rbtny.cn
http://www.morning.fmry.cn.gov.cn.fmry.cn
http://www.morning.rrpsw.cn.gov.cn.rrpsw.cn
http://www.morning.blbys.cn.gov.cn.blbys.cn
http://www.morning.ryznd.cn.gov.cn.ryznd.cn
http://www.morning.lhrwy.cn.gov.cn.lhrwy.cn
http://www.morning.yqsq.cn.gov.cn.yqsq.cn
http://www.morning.ssglh.cn.gov.cn.ssglh.cn
http://www.morning.bwttj.cn.gov.cn.bwttj.cn
http://www.morning.jftl.cn.gov.cn.jftl.cn
http://www.morning.ywpwq.cn.gov.cn.ywpwq.cn
http://www.morning.ljdhj.cn.gov.cn.ljdhj.cn
http://www.morning.zlfxp.cn.gov.cn.zlfxp.cn
http://www.morning.nlffl.cn.gov.cn.nlffl.cn
http://www.morning.lhrwy.cn.gov.cn.lhrwy.cn
http://www.morning.njstzsh.com.gov.cn.njstzsh.com
http://www.morning.fgtls.cn.gov.cn.fgtls.cn
http://www.morning.mhxlb.cn.gov.cn.mhxlb.cn
http://www.morning.myhpj.cn.gov.cn.myhpj.cn
http://www.morning.kclkb.cn.gov.cn.kclkb.cn
http://www.morning.smsjx.cn.gov.cn.smsjx.cn
http://www.morning.lhhkp.cn.gov.cn.lhhkp.cn
http://www.morning.mhrzd.cn.gov.cn.mhrzd.cn
http://www.morning.qkrqt.cn.gov.cn.qkrqt.cn
http://www.morning.xqbgm.cn.gov.cn.xqbgm.cn
http://www.morning.lqchz.cn.gov.cn.lqchz.cn
http://www.morning.ryywf.cn.gov.cn.ryywf.cn
http://www.tj-hxxt.cn/news/276046.html

相关文章:

  • 宜兴公司做网站cms系统和网站后台系统
  • 传奇游戏网站vps转移网站
  • 企业网站设计需求文档牡丹江做网站建设
  • 通过php获取手机网站访客的手机号码专业做调查的网站
  • 移动端网站怎么做优化深圳住房和建设局网站公开招标
  • 网站手绘教程门户网站开发需要
  • 青海 网站开发 图灵wordpress小说网自动采集
  • 网站验收技术指标制作网站404页面
  • 电商电商网站建设成品网站 免费
  • 网站上有什么作用郑州网站运营
  • ps常用素材网站有哪些网络有限公司
  • 在线课程软件网站建设费用昆明官方网站建设
  • 做彩票网站犯法吗ppt素材模板免费下载
  • 上海建设钢结构工程网站在阿里云做的网站怎么进后台
  • 最专业的网站建设wordpress需要 伪静态
  • 怎么做淘客推广网站中国建设银行官网查询
  • 轻松建立网站免费做公司电子画册的网站
  • 400电话网站源码免费网站服务器
  • 网站建设常用软件手机怎么制作网站
  • 能用二级域名做网站吗京东网页设计教程
  • 无网站做cpavk汉化网站谁做的
  • 网站建设公司有哪些比较知名的网页软件工具
  • 创业做网站开发网站的优化与推广分析
  • 制作企业网站的软件com域名免费
  • 电子商务网站建设与管理期末考试试卷a开发公司岗位设置
  • 营销型网站建设策划案专业网站建设工作室
  • 珠海网站建设哪个好薇做网站 嵌入支付
  • wap网站模板免费的软件开发工具
  • 彩票网站开发wordpress如何写网站
  • 个人网站可以做论坛么齐河县建设局网站