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

如何做好网站seo互联网营销师国家职业技能标准

如何做好网站seo,互联网营销师国家职业技能标准,奶精粉制作奶茶怎么做,wordpress无法显示中文Stream流 把数据放进stream流水线,对数据进行一系列操作(中间方法),最后封装(终结方法)。 Stream.of()允许传入任何参数 常见中间方法 可以对数据进行链式(流水线)操作,但…
Stream流

把数据放进stream流水线,对数据进行一系列操作(中间方法),最后封装(终结方法)。

Stream.of()允许传入任何参数

  • 常见中间方法

    可以对数据进行链式(流水线)操作,但中间方法返回的都是stream对象

    Stream.of(1, 2, 3, 4, 5).filter(n -> n % 2 == 0) // 只保留偶数.forEach(System.out::println);//打印Stream.of("a", "b", "c").map(String::toUpperCase) // 将每个字符串转换为大写.forEach(System.out::println);Stream.of(1, 2, 2, 3, 4, 4).distinct().forEach(System.out::println); // 输出 1, 2, 3, 4Stream.of(5, 3, 1, 4, 2).sorted() // 默认升序排序.forEach(System.out::println);Stream.of(1, 2, 3, 4, 5).limit(3) // 只保留前 3 个元素.forEach(System.out::println);Stream.of(1, 2, 3, 4, 5).skip(2) // 跳过前 2 个元素.forEach(System.out::println); // 输出 3, 4, 5Stream().map()//将流中的每一个数据转化为另一种形式,并返回新流
    //1数据转化
    List<String> strings = Arrays.asList("apple", "banana", "cherry");
    List<String> upperCaseStrings = strings.stream().map(String::toUpperCase)//转化为大写.collect(Collectors.toList());
    System.out.println("Upper Case Strings: " + upperCaseStrings);Upper Case Strings: [APPLE, BANANA, CHERRY]//2数据处理
    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
    List<Integer> squaredNumbers = numbers.stream().map(n -> n * n)//获得平方.collect(Collectors.toList());
    System.out.println("Squared Numbers: " + squaredNumbers);Squared Numbers: [1, 4, 9, 16, 25]//3复杂对象转化
    class User {String name;int age;User(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}
    }List<User> users = Arrays.asList(new User("Alice", 23),new User("Bob", 17),new User("Charlie", 25)
    );List<String> userNames = users.stream().map(User::getName)//获得对象里的名字.collect(Collectors.toList());//并以list返回
    System.out.println("User Names: " + userNames);User Names: [Alice, Bob, Charlie]
  • 常见终结方法

    终结方法会结束流的操作,并返回一个结果,如基本类型(double,string等),或对象(List,map等),特殊值(void等)

    Stream.of("a", "b", "c").forEach(System.out::println);List<String> list = Stream.of("a", "b", "c").collect(Collectors.toList());Stream().reduce()
    int sum = Stream.of(1, 2, 3, 4).reduce(0, Integer::sum);
    reduce 方法允许我们将流中的元素组通过操作(求和、求积、连接字符串等)合成一个单一的结果。它接收两个参数:
    初始值(identity):归约操作的初始值,如果流为空,则返回该值。
    累加器(accumulator):用于将流中的元素累积到一个结果中的函数。
    求和为例:
    public class ReduceExamples {public static void main(String[] args) {List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);// 使用 reduce 求和int sum = numbers.stream().reduce(0, (a, b) -> a + b);//0为初始值,如果流中没有数据返回的值//(a, b) -> a + b是将前一个累积值a加上当前流上的数据bSystem.out.println("Sum of numbers: " + sum); // 输出:Sum of numbers: 15}
    }复杂对象(苍穹外卖)为例:
    //计算规定天数内的所有订单总量
    Integer allOrder = orderList.stream().reduce(Integer::sum).get();//其中orderList是每天的订单总量,这里将每天订单量求和了。//如果集合里存的是对象,若想获得对象里的其中值和:
    public class ReduceExamples {public static void main(String[] args) {List<Product> products = Arrays.asList(new Product("iPhone", 999.99),new Product("Laptop", 1499.99),new Product("Headphones", 199.99));// 使用 reduce 求产品价格总和double totalPrice = products.stream().mapToDouble(Product::getPrice)//通过 mapToDouble 将 Product 对象映射为其价格.reduce(0, Double::sum);System.out.println("Total price of products: " + totalPrice); // 输出:Total price of products: 2699.97}
    }long count = Stream.of("a", "b", "c").count();//数据数量boolean hasA = Stream.of("a", "b", "c").anyMatch(s -> s.equals("a"));//数据中是否有满足的boolean allMatch = Stream.of(1, 2, 3).allMatch(n -> n < 5);//数据是否全部满足Optional<String> first = Stream.of("a", "b", "c").findFirst();//数据如果有,返回第一个
http://www.dt0577.cn/news/4190.html

相关文章:

  • 网站文字很少怎么做优化深圳全网推广效果如何
  • 青岛网站制作选ls15227seo线上培训班
  • 视觉设计评价标准的要素seo如何进行优化
  • 在东营怎么建网站网站推广工具
  • 电子商务网站开发公司网站平台搭建
  • 福州市网站建设销售网络平台推广
  • 怎么在云主机上做网站最新病毒感染
  • 网站开发公司 logo网站营销方案模板
  • 苹果手机做微电影网站有哪些内容培训机构退费法律规定
  • 为什么做网站最近一周新闻大事
  • 给公司网站做seo的好处石家庄seo排名公司
  • 武汉营销型网站设计网站seo推广员招聘
  • 有数据库的网站厦门人才网唯一官方网站
  • 电子商务网站开发课程长沙排名推广
  • 自适应网站功能百度推广怎么登陆
  • 做图表的网站推荐网页设计需要学什么
  • 什么网站可以做论坛app引流推广公司
  • 怒江网站制作他达拉非什么是
  • 中小企业网站建设咨询大数据分析
  • 广州地址设计网站seo网址大全
  • 为什么很少用python做网站搜索词
  • wordpress给公司建站alexa排名查询
  • 建站工具论坛以服务营销出名的企业
  • 做宣传的视频网站有哪些系列推广软文范例
  • 怎么做报名网站台州关键词优化推荐
  • 在线咨询网站开发价格徐州网页关键词优化
  • 业务员自己掏钱做网站可以吗网上有免费的网站吗
  • 企业概况的内容做好的网站怎么优化
  • 做微信的网站有哪些功能网络关键词优化方法
  • WordPress文章开启评论北京seo外包公司要靠谱的