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

制作网站费用淘宝网站图片维护怎么做

制作网站费用,淘宝网站图片维护怎么做,网上书店网站建设方案策划,购买商标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.pierceye.com/news/728305/

相关文章:

  • vue做网站首页做网站 上海
  • 建设一个商务网站的步骤做网站购买空间多少钱
  • 哈尔滨网站制作注册公司有什么风险
  • 自己做网站不如帮别人做运营网站开发计划怎么写
  • 飘雪影视在线观看免费完整台州网站排名优化价格
  • 网站制作要钱吗seo的培训网站哪里好
  • 图片类网站如何做优化装潢设计培训中心
  • 哪里做网站做得好宿迁网站建设sq918
  • 中企动力 网站建设那些网站是做俄罗斯鞋子
  • jsp怎么做购物网站建设营销型网站多少钱
  • 东莞网站设免费的网站程序哪里好
  • 网站主页用ps做免费网站建站有哪些
  • 锦州网站建设公司湘潭市高新建设局施工报建网站
  • 前端网站开发江阴外贸网站建设
  • 手机网站建设的整体流程seo是什么职位的简称
  • 川畅咨询 做网站多少钱注册企业邮箱要钱吗
  • 网站制作成本包含游戏咨询网站建设目标是什么
  • 江门seo网站推广做网站营销怎么去推广
  • 厦门网站建设系统深圳网站建设骏域网站建设
  • 工商网站备案查询建设新农村网站
  • 建筑网站资料排行榜移动互联网的概念是什么
  • 浙江省建设诚信系统网站网上购物哪个网站最好
  • 做网站电销和生活爱辽宁下载安装
  • 安监网站安全建设信息wordpress电影影视主题
  • 网站打不开服务器错误网站怎么设置支付
  • 做网站的宽度为多少云南省建设工程信息服务平台
  • 网站优化公司大家好桂林网络搭建
  • 做a漫画在线观看网站网站建设这个工作怎么样
  • 商城网站建设缺点培训机构退费
  • 大型网站需要什么样的团队建购物网站 教程