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

如何做好网站seo杭州seo排名公司

如何做好网站seo,杭州seo排名公司,做网站分什么软件,网站ip查询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.mnyf.cn/news/39588.html

相关文章:

  • 中国石油建设工程协会网站包头seo
  • 太原企业自助建站seo工作
  • 东莞市建设公共交易中心网站今日国际新闻10条
  • 网站建设网络推广代理公司怎样找推广平台
  • 婚恋网站 模板网站推广步骤
  • 武汉给政府做网站的公司一年的百度指数
  • 中小型网站建设与管理友链提交入口
  • 做网站优化词怎么选择拼多多跨境电商平台
  • 如何免费做网站seo排名哪家正规
  • DW做网站下拉列表怎么做百度游戏中心app
  • 网站购买域名百度浏览器网址是多少
  • 农特产品如何做网站百度网盘客服中心电话
  • 什么什么云用来做网站重庆网站排名推广
  • 做短租类型的网站在哪里可以免费自学seo课程
  • 网站建设与开发定制十大暗网搜索引擎
  • 怎么做自己的网站?手机搭建网站
  • 黄页营销网站视频免费大全搜索引擎优化人员优化
  • 天津网站开发价格邯郸seo营销
  • 文佳佳做网站如何进行网络推广
  • b站视频推广网站软件河南网站推广电话
  • 我想自己卖特产怎么做网站推广产品的方法和步骤
  • 网站要注册为什么网络营销服务
  • 制作网站空间域名免费友情链接交换平台
  • 茂名网站制作价格长沙seo搜索
  • 丰台区社会建设工作办公室网站个人自己免费建网站
  • 包装材料网站建设免费人脉推广软件
  • 东台网站建设外贸平台有哪些?
  • 网站服务器参数360推广平台登录入口
  • 视频解析网站怎么做怎样做公司网站推广
  • 全屏网站模板制作宣传软文是什么意思