Java基础(二十六):Java8 Stream流及Optional类

Java基础系列文章

Java基础(一):语言概述

Java基础(二):原码、反码、补码及进制之间的运算

Java基础(三):数据类型与进制

Java基础(四):逻辑运算符和位运算符

Java基础(五):流程控制语句

Java基础(六):数组

Java基础(七):面向对象编程

Java基础(八):封装、继承、多态性

Java基础(九):Object 类的使用

Java基础(十):关键字static、代码块、关键字final

Java基础(十一):抽象类、接口、内部类

Java基础(十二):枚举类

Java基础(十三):注解(Annotation)

Java基础(十四):包装类

Java基础(十五):异常处理

Java基础(十六):String的常用API

Java基础(十七):日期时间API

Java基础(十八):java比较器、系统相关类、数学相关类

Java基础(十九):集合框架

Java基础(二十):泛型

Java基础(二十一):集合源码

Java基础(二十二):File类与IO流

Java基础(二十三):反射机制

Java基础(二十四):网络编程

Java基础(二十五):Lambda表达式、方法引用、构造器引用

Java基础(二十六):Java8 Stream流及Optional类


目录

  • 一、Stream介绍
    • 1、什么是Stream
    • 2、Stream特点
    • 3、Stream的操作三个步骤
  • 二、创建Stream实例
    • 1、通过集合创建Stream
    • 2、通过数组创建Stream
    • 3、通过Stream的of()创建Stream
    • 4、创建无限流
  • 三、Stream中间操作
    • 1、筛选(filter)
    • 2、截断(limit)
    • 3、跳过(skip)
    • 4、去重(distinct)
    • 5、映射(map/flatMap/mapToInt)
    • 6、排序(sorted)
    • 7、peek 和 forEach
  • 四、Stream终止操作
    • 1、匹配(allMatch/anyMatch/noneMatch)
    • 2、查找(findFirst/findAny)
    • 3、聚合(max/min/count)
    • 4、归约(reduce)
    • 5、收集(collect)
      • 5.1、归集(toList/toSet/toMap)
      • 5.2、统计(counting/averaging/summing/maxBy/minBy)
      • 5.3、分组(partitioningBy/groupingBy)
      • 5.4、接合(joining)
  • 五、Optional 类
    • 1、构建Optional对象
    • 2、获取value值,空值的处理
    • 3、处理value值,空值不处理不报错


一、Stream介绍

1、什么是Stream

  • Stream 是数据渠道,用于操作数据源(集合、数组等)所生成的元素序列
  • Stream和Collection集合的区别
    • Collection是一种静态的内存数据结构,讲的是数据;主要面向内存,存储在内存中
    • Stream是有关计算的,讲的是计算;面向CPU,通过CPU实现计算

2、Stream特点

  1. Stream自己不会存储元素
  2. Stream不会改变源对象。相反,他们会返回一个持有结果的新Stream
  3. Stream 操作是延迟执行的
    • 这意味着他们会等到需要结果的时候才执行
    • 即一旦执行终止操作,就执行中间操作链,并产生结果
  4. Stream一旦执行了终止操作,就不能再调用其它中间操作终止操作

3、Stream的操作三个步骤

  1. 创建 Stream
    • 一个数据源(如:集合、数组),获取一个流
  2. 中间操作
    • 每次处理都会返回一个持有结果的新Stream
    • 即中间操作的方法返回值仍然是Stream类型的对象
    • 因此中间操作可以是个操作链,可对数据源的数据进行n次处理
    • 但是在终结操作前,并不会真正执行
  3. 终止操作(终端操作)
    • 终止操作的方法返回值类型就不再是Stream了
    • 因此一旦执行终止操作,就结束整个Stream操作了
    • 一旦执行终止操作,就执行中间操作链,最终产生结果并结束Stream

在这里插入图片描述

二、创建Stream实例

1、通过集合创建Stream

  • Java8中的Collection接口被扩展,提供了两个获取流的方法:
    • default Stream<E> stream() : 返回一个顺序流
    • default Stream<E> parallelStream() : 返回一个并行流
@Test
public void test01(){
	List<String> list = Arrays.asList("a", "b", "c", "d");
	//创建顺序流(顺序执行)
	Stream<String> stream = list.stream();
	//创建并行流(多线程并行执行,速度快)
	Stream<String> parallelStream = list.parallelStream();
}

2、通过数组创建Stream

  • Java8 中的 Arrays 的静态方法 stream() 可以获取数组流:
    • public static <T> Stream<T> stream(T[] array): 返回一个流
    • public static IntStream stream(int[] array)
    • public static LongStream stream(long[] array)
    • public static DoubleStream stream(double[] array)
@Test
public void test02(){
    String[] arr = {"hello","world"};
    Stream<String> stream = Arrays.stream(arr); 
}

@Test
public void test03(){
    int[] arr = {1,2,3,4,5};
    IntStream stream = Arrays.stream(arr);
}

3、通过Stream的of()创建Stream

  • 可以调用Stream类静态方法 of(), 通过显示值创建一个流
  • 它可以接收任意数量的参数
    • public static<T> Stream<T> of(T… values) : 返回一个流
@Test
public void test04(){
    Stream<Integer> stream = Stream.of(1,2,3,4,5);
    stream.forEach(System.out::println);
}

4、创建无限流

  • 可以使用静态方法 Stream.iterate() 和 Stream.generate(), 创建无限流
    • public static<T> Stream<T> iterate(final T seed, final UnaryOperator<T> f)
    • public static<T> Stream<T> generate(Supplier<T> s)
@Test
public void test05() {
	// 迭代累加,获取前五个
	Stream<Integer> stream = Stream.iterate(1, x -> x + 2);
	stream.limit(5).forEach(System.out::println);

    System.out.println("**********************************");
    
	// 一直生成随机数,获取前五个
	Stream<Double> stream1 = Stream.generate(Math::random);
	stream1.limit(5).forEach(System.out::println);
}

输出结果:

1
3
5
7
9
**********************************
0.1356905695577818
0.33576714141304886
0.7325647295361851
0.29218866245097375
0.24849848127040652

三、Stream中间操作

  • 多个中间操作可以连接起来形成一个流水线,除非流水线上触发终止操作,否则中间操作不会执行任何的处理
  • 而在终止操作时一次性全部处理,称为“惰性求值”

准备测试数据

// @Data 注在类上,提供类的get、set、equals、hashCode、toString等方法
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Employee {
	// id
	private int id;
	// 名称
	private String name;
	// 年龄
	private int age;
	// 工资
	private double salary;
}

public class EmployeeData {
	public static List<Employee> getEmployees(){
		List<Employee> list = new ArrayList<>();
		list.add(new Employee(1001, "马化腾", 34, 6000.38));
		list.add(new Employee(1002, "马云", 2, 19876.12));
		list.add(new Employee(1003, "刘强东", 33, 3000.82));
		list.add(new Employee(1004, "雷军", 26, 7657.37));
		list.add(new Employee(1005, "李彦宏", 65, 5555.32));
		list.add(new Employee(1006, "比尔盖茨", 42, 9500.43));
		list.add(new Employee(1007, "任正非", 26, 4333.32));
		list.add(new Employee(1008, "扎克伯格", 35, 2500.32));
		return list;
	}
}

1、筛选(filter)

  • 查询员工表中薪资大于7000的员工信息
// 获取员工集合数据
List<Employee> employeeList = EmployeeData.getEmployees();
Stream<Employee> stream = employeeList.stream();
stream.filter(emp -> emp.getSalary() > 7000).forEach(System.out::println);

2、截断(limit)

  • 获取员工集合数据的前十个员工信息
employeeList.stream().limit(10).forEach(System.out::println);

3、跳过(skip)

  • 返回一个删除前五个员工信息的数据,与limit(n)互补
employeeList.stream().skip(5).forEach(System.out::println);

4、去重(distinct)

  • 通过流所生成元素的hashCode()和equals()去除重复元素
  • 需要重写hashCode和equals方法,否则不能去重
employeeList.add(new Employee(1009, "马斯克", 40, 12500.32));
employeeList.add(new Employee(1009, "马斯克", 40, 12500.32));
employeeList.add(new Employee(1009, "马斯克", 40, 12500.32));
employeeList.add(new Employee(1009, "马斯克", 40, 12500.32));

employeeList.stream().distinct().forEach(System.out::println);

5、映射(map/flatMap/mapToInt)

  • map:获取员工姓名长度大于3的员工的姓名
//方式1:Lambda表达式
employeeList.stream().map(emp -> emp.getName())
        .filter(name -> name.length() > 3).forEach(System.out::println);
//方式2:方法引用第三种 类 :: 实例方法名
employeeList.stream().map(Employee::getName)
        .filter(name -> name.length() > 3).forEach(System.out::println);
  • flatMap:当处理嵌套集合时,可以使用flatMap将嵌套集合展平成一个新的Stream
List<List<Integer>> nestedList = Arrays.asList(
        Arrays.asList(1, 2, 3),
        Arrays.asList(4, 5, 6),
        Arrays.asList(7, 8, 9)
);

nestedList.stream()
        .flatMap(item -> item.stream())
        .forEach(System.out::println);
  • mapToInt:将流中每个元素映射为int类型
// 获取名字长度的总和
List<String> list1 = Arrays.asList("Apple", "Banana", "Orange", "Grapes");
IntStream intstream = list1.stream().mapToInt(String::length);
int sum = intstream.sum();
  • mapToDouble:将流中每个元素映射为Double类型
  • mapToLong:将流中每个元素映射为Long类型

6、排序(sorted)

  • sorted():自然排序(从小到大),流中元素需实现Comparable接口,否则报错
//sorted() 自然排序
Integer[] arr = new Integer[]{345,3,64,3,46,7,3,34,65,68};
String[] arr1 = new String[]{"GG","DD","MM","SS","JJ"};

Arrays.stream(arr).sorted().forEach(System.out::println);
Arrays.stream(arr1).sorted().forEach(System.out::println);

//因为Employee没有实现Comparable接口,所以报错!
employeeList.stream().sorted().forEach(System.out::println);
  • sorted(Comparator com):Comparator排序器自定义排序
// 根据工资自然排序(从小到大)
employeeList.stream().sorted(Comparator.comparing(Employee::getSalary))
                .forEach(System.out::println);
// 根据工资倒序(从大到小)  
employeeList.stream().sorted(Comparator.comparing(Employee::getSalary).reversed())
                .forEach(System.out::println);

7、peek 和 forEach

  • 相同点:peek和forEach都是遍历流内对象并且对对象进行一定的操作
  • 不同点:forEach返回void结束Stream操作,peek会继续返回Stream对象
employeeList.stream()
        .map(Employee::getName)
        .peek(System.out::println)
        .filter(name -> name.length() > 3)
        .forEach(System.out::println);

四、Stream终止操作

  • 终端操作会从流的流水线生成结果。其结果可以是任何不是流的值,例如:List、Integer,甚至是 void
  • 流进行了终止操作后,不能再次使用

1、匹配(allMatch/anyMatch/noneMatch)

  • allMatch(Predicate p):检查是否匹配所有元素
  • 是否所有的员工的年龄都大于18
boolean allMatch = employeeList.stream().allMatch(emp -> emp.getAge() > 18);
  • anyMatch(Predicate p):检查是否至少匹配一个元素
  • 是否存在年龄大于18岁的员工
boolean anyMatch = employeeList.stream().anyMatch(emp -> emp.getAge() > 18);
  • noneMatch(Predicate p):检查是否没有匹配所有元素
  • 是不是没有年龄大于18岁的员工,没有返回true,存在返回false
boolean noneMatch = employeeList.stream().noneMatch(emp -> emp.getAge() > 18);

2、查找(findFirst/findAny)

  • findFirst():返回第一个元素
Optional<Employee> first = employeeList.stream().findFirst();
Employee employee = first.get();
  • findAny():返回当前流中的任意元素
Optional<Employee> any = employeeList.stream().findAny();
Employee employee = any.get();

ps:集合中数据为空,会抛异常No value present,后面会将Optional类的空值处理

3、聚合(max/min/count)

  • max(Comparator c):返回流中最大值,入参与排序sorted的比较器一样,必须自然排序
  • 返回最高工资的员工
Optional<Employee> max = employeeList.stream().max(Comparator.comparingDouble(Employee::getSalary));
Employee employee = max.get();
  • min(Comparator c):返回流中最小值,入参与排序sorted的比较器一样,必须自然排序
  • 返回最低工资的员工
Optional<Employee> min = employeeList.stream().min(Comparator.comparingDouble(Employee::getSalary));
Employee employee = min.get();
  • count():返回流中元素总数
  • 返回所有工资大于7000的员工的个数
long count = employeeList.stream().filter(emp -> emp.getSalary() > 7000).count();

4、归约(reduce)

  • reduce(BinaryOperator b):可以将流中元素反复结合起来,得到一个值。返回 Optional<T>
// 计算1-10的自然数的和
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Optional<Integer> reduce6 = list.stream().reduce(Integer::sum);
Integer sum = reduce6.get();

// 计算公司所有员工工资的总和
Optional<Double> reduce7 = employeeList.stream().map(Employee::getSalary).reduce(Double::sum);
Double aDouble = reduce7.get();
  • reduce(T identity, BinaryOperator b):可以将流中元素反复结合起来,得到一个值。返回 T
  • T identity:累加函数的初始值
  • 不需要先获取Optional再get(),直接可以获取结果,推荐使用
// 计算1-10的自然数的和
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
Integer reduce1 = list.stream().reduce(0, (x1, x2) -> x1 + x2);
Integer reduce2 = list.stream().reduce(0, (x1, x2) -> Integer.sum(x1, x2));
Integer reduce3 = list.stream().reduce(0, Integer::sum);
// 计算1-10的自然数的乘积
Integer reduce4 = list.stream().reduce(1, (x1, x2) -> x1 * x2);

// 计算公司所有员工工资的总和
Double reduce5 = employeeList.stream().map(Employee::getSalary).reduce(0.0, Double::sum);

5、收集(collect)

  • collect(Collector c):将流转换为其他形式,接收一个Collector接口的实现,用于给Stream中元素做汇总的方法
  • Collector接口中方法的实现决定了如何对流执行收集的操作(如收集到 List、Set、Map)
  • Collectors实用类提供了很多静态方法,可以方便地创建常见收集器实例,如下

5.1、归集(toList/toSet/toMap)

  • toList():把流中元素收集到List
  • 获取所有员工姓名集合
List<String> nameList1 = employeeList.stream().map(Employee::getName).collect(Collectors.toList());
// jdk16以后,collect(Collectors.toList())可以简写为.toList()
List<String> nameList2 = employeeList.stream().map(Employee::getName).toList();
  • toSet():把流中元素收集到Set
  • 获取所有员工年龄set集合,可以去重
Set<Integer> ageList = employeeList.stream().map(Employee::getAge).collect(Collectors.toSet());
  • toMap():把流中元素收集到Map
  • Function.identity():t -> t,相当于参数是什么,返回什么

如下如果key重复,会抛异常java.lang.IllegalStateException: Duplicate key xxx

// key-名称 value-员工对象
Map<String, Employee> employeeNameMap = employeeList.stream()
        .collect(Collectors.toMap(Employee::getName, Function.identity()));
// key-名称 value-工资
Map<String, Double> nameSalaryMap = employeeList.stream()
        .collect(Collectors.toMap(Employee::getName, Employee::getSalary));
  • toMap的第三个参数则是key重复后如何操作value的内容
  • key重复可以只要旧的value数据,也可以新的value+旧的value等等
// key-名称 value-员工对象
Map<String, Employee> employeeNameMap = employeeList.stream()
        .collect(Collectors.toMap(Employee::getName, Function.identity(),(oldValue,newValue) -> oldValue));
// key-名称 value-工资
Map<String, Double> nameSalaryMap = employeeList.stream()
        .collect(Collectors.toMap(Employee::getName, Employee::getSalary,(oldValue,newValue) -> oldValue + newValue));

5.2、统计(counting/averaging/summing/maxBy/minBy)

  • counting():计算流中元素的个数
Long count = employeeList.stream().collect(Collectors.counting());
// 相当于
Long count2 = employeeList.stream().count();
  • averagingInt:计算流中元素Integer属性的平均值
  • averagingDouble:计算流中元素Double属性的平均值
  • averagingLong:计算流中元素Long属性的平均值
  • 返回值都是Double
Double aDouble = employeeList.stream().collect(Collectors.averagingInt(Employee::getAge));
Double bDouble = employeeList.stream().collect(Collectors.averagingDouble(Employee::getSalary));
  • summingInt:计算流中元素Integer属性的总和
  • summingDouble:计算流中元素Double属性的总和
  • summingLong:计算流中元素Long属性的总和
Integer count = employeeList.stream().collect(Collectors.summingInt(Employee::getAge));
Double total = employeeList.stream().collect(Collectors.summingDouble(Employee::getSalary));
  • maxBy():计算流最大值
  • minBy():计算流最小值
// 最大值
Optional<Employee> employee = employeeList.stream()
       .collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));
// 最小值
Optional<Employee> employee = employeeList.stream()
        .collect(Collectors.minBy(Comparator.comparingDouble(Employee::getSalary)));
  • summarizingInt():汇总统计包括总条数、总和、平均数、最大值、最小值
IntSummaryStatistics summaryStatistics = employeeList.stream().collect(Collectors.summarizingInt(Employee::getAge));
System.out.println(summaryStatistics);// IntSummaryStatistics{count=8, sum=263, min=2, average=32.875000, max=65}

5.3、分组(partitioningBy/groupingBy)

  • partitioningBy():根据true或false进行分区
  • 将员工按薪资是否高于6000分组
Map<Boolean, List<Employee>> listMap = employeeList.stream()
        .collect(Collectors.partitioningBy(emp -> emp.getSalary() > 6000));
  • groupingBy():根据某属性值对流分组,属性为K,结果为V
  • 将员工年龄分组
Map<Integer, List<Employee>> collect = employeeList.stream()
        .collect(Collectors.groupingBy(Employee::getAge));
  • 将员工按年龄分组,再汇总不同年龄的总金额
Map<Integer, Double> collect = employeeList.stream()
        .collect(Collectors.groupingBy(Employee::getAge, Collectors.summingDouble(Employee::getSalary)));
  • 将员工按年龄分组,获取工资集合
Map<Integer, List<Double>> integerListMap = employeeList.stream()
        .collect(Collectors.groupingBy(Employee::getAge, 
                Collectors.mapping(Employee::getSalary, Collectors.toList())));
  • 先按员工年龄分组,再按工资分组
Map<Integer, Map<Double, List<Employee>>> collect = employeeList.stream()
        .collect(Collectors.groupingBy(Employee::getAge, Collectors.groupingBy(Employee::getSalary)));

5.4、接合(joining)

List<String> list = Arrays.asList("A", "B", "C");
String string = list.stream().collect(Collectors.joining("-"));
// 结果:A-B-C

五、Optional 类

Optional类内部结构(value为实际存储的值)

public final class Optional<T> {
    // 空Optional对象,value为null
    private static final Optional<?> EMPTY = new Optional<>();

    // 实际存储的内容
    private final T value;

    // 私有的构造
    private Optional() {
        this.value = null;
    }
    
	...
}

1、构建Optional对象

@Test
public void optionalTest(){
    Integer value1 = null;
    Integer value2 = 10;
    // 允许传递为null参数
    Optional<Integer> a = Optional.ofNullable(value1);
    // 如果传递的参数是null,抛出异常NullPointerException
    Optional<Integer> b = Optional.of(value2);
    // 空对象,value为null
    Optional<Object> c = Optional.empty();
}

2、获取value值,空值的处理

@Test
public void optionalTest() {
    Integer value1 = null;
    Optional<Integer> a = Optional.ofNullable(value1);
    System.out.println("value值是否为null:" + a.isPresent());
    System.out.println("获取value值,空报错空指针:" + a.get());
    System.out.println("获取value值,空返回默认值0:" + a.orElse(0));
    System.out.println("获取value值,空返回Supplier返回值:" + a.orElseGet(() -> 100));
    System.out.println("获取value值,空抛出异常:" + a.orElseThrow(() -> new RuntimeException("value为空")));
}

3、处理value值,空值不处理不报错

  • ifPresent方法内会判断不为空才操作
@Test
public void optionalTest() {
    Integer value1 = 10;
    Optional<Integer> a = Optional.ofNullable(value1);
    // 空不处理,非空则根据Consumer消费接口处理
    a.ifPresent(o -> System.out.println("ifPresent value值:" + o)); // 10
    // 空不处理,filter过滤
    a.filter(o -> o > 1).ifPresent(o -> System.out.println("filter value值:" + o)); // 10
    // 空不处理,map映射
    a.map(o -> o + 10).ifPresent(o -> System.out.println("map value值:" + o)); // 20
    // 空不处理,flatMap映射
    a.flatMap(o -> Optional.of(o + 20)).ifPresent(o -> System.out.println("flatMap value值:" + o)); // 30
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/400587.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

外汇天眼:交易讲究时机,不要在这几个时间交易

每个交易者都想知道&#xff0c;什么时候是入场买卖的最好时机。 到底是1.1800入场呢&#xff1f; 还是等到1.1900&#xff1f; 但是&#xff0c;交易中不仅仅是关于从哪里入场&#xff0c;同样的&#xff0c;知道什么时候不去交易也是非常重要的。 这听起来像是一回事&#x…

私房菜|私房菜定制上门服务系统|基于springboot+vue私房菜定制上门服务系统设计与实现(源码+数据库+文档)

私房菜定制上门服务系统目录 目录 基于springbootvue私房菜定制上门服务系统设计与实现 一、前言 二、系统功能设计 三、系统实现 1、管理员功能实现 &#xff08;1&#xff09;菜品管理 &#xff08;2&#xff09;公告管理 &#xff08;3&#xff09; 厨师管理 2、用…

04 动力云客之登录后获取用户信息+JWT存进Redis+Filter验证Token + token续期

1. 登录后获取用户信息 非常好实现. 只要新建一个controller, 并调用SS提供的Authentication对象即可 package com.sunsplanter.controller;RestController public class UserController {GetMapping(value "api/login/info")public R loginInfo(Authentication a…

IO进程线程day5作业

1、使用多线程完成两个文件的拷贝&#xff0c;第一个线程拷贝前一半&#xff0c;第二个线程拷贝后一半&#xff0c;主线程回收两个线程的资源 代码&#xff1a; #include<myhead.h>//定义文件拷贝函数 int copy_file(int start,int len) {int srcfd,destfd;//以只读的形…

MySQL 安装步骤

下载地址&#xff1a;https://downloads.mysql.com/archives/community/&#xff0c; 选择第二个 将下载的压缩包解压到自己想要放到的目录下&#xff08;路径中最好不要有中文&#xff09; 一、添加环境变量 环境变量里面有很多选项&#xff0c;这里我们只用到Path这个参数…

微信小程序错误----config is not defined

微信小程序出错 请求头发生错误 修改 options.header {// 为请求头对象添加 token 验证的 Authorization 字段Access-Token: token,platform: MP-WEIXIN,// 保留原有的 header...options.header,}

【Java程序员面试专栏 数据结构】四 高频面试算法题:哈希表

一轮的算法训练完成后,对相关的题目有了一个初步理解了,接下来进行专题训练,以下这些题目就是汇总的高频题目,一个O(1)查找的利器哈希表,所以放到一篇Blog中集中练习 题目关键字解题思路时间空间两数之和辅助哈希使用map存储出现过的值,key为值大小,value为下标位置,…

Vue+SpringBoot打造超市商品管理系统

目录 一、摘要1.1 简介1.2 项目录屏 二、研究内容2.1 数据中心模块2.2 超市区域模块2.3 超市货架模块2.4 商品类型模块2.5 商品档案模块 三、系统设计3.1 用例图3.2 时序图3.3 类图3.4 E-R图 四、系统实现4.1 登录4.2 注册4.3 主页4.4 超市区域管理4.5 超市货架管理4.6 商品类型…

伦敦金行情分析需要学习吗?

对于伦敦金交易来说&#xff0c;目前大致分成两派&#xff0c;一派是实干派&#xff0c;认为做伦敦金交易重要的是实战&#xff0c;不需要学习太多东西&#xff0c;否则容易被理论知识所局限。另一派则是强调学习&#xff0c;没有理论知识&#xff0c;投资者很难做好伦敦金交易…

什么是接口测试?为什么要做接口测试?

1. 什么是接口测试&#xff1f;为什么要做接口测试&#xff1f; 接口测试是测试系统组件间接口的一种测试。接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点。测试的重点是要检查数据的交换&#xff0c;传递和控制管理过程&#xff0c;以及系统间的相互…

Web自动化测试 Selenium 1/3

&#x1f525; 交流讨论&#xff1a;欢迎加入我们一起学习&#xff01; &#x1f525; 资源分享&#xff1a;耗时200小时精选的「软件测试」资料包 &#x1f525; 教程推荐&#xff1a;火遍全网的《软件测试》教程 &#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1…

Spring Framework

Spring Framework Spring 是一款开源的轻量级 Java 开发框架&#xff0c;旨在提高开发人员的开发效率以及系统的可维护性。 Spring 框架指的都是 Spring Framework&#xff0c;它是很多模块的集合&#xff0c;如下图所示&#xff1a; 一、Core Container Spring 框架的核心模…

Atcoder ABC341 B - Foreign Exchange

Foreign Exchange&#xff08;外汇&#xff09; 时间限制&#xff1a;2s 内存限制&#xff1a;1024MB 【原题地址】 所有图片源自Atcoder&#xff0c;题目译文源自脚本Atcoder Better! 点击此处跳转至原题 【问题描述】 【输入格式】 【输出格式】 【样例1】 【样例输入1…

【JavaEE】_form表单构造HTTP请求

目录 1. form表单的格式 1.1 form表单的常用属性 1.2 form表单的常用搭配标签&#xff1a;input 2. form表单构造GET请求实例 3. form表单构造POST请求实例 4. form表单构造法的缺陷 对于客户端浏览器&#xff0c;以下操作即构造了HTTP请求&#xff1a; 1. 直接在浏览器…

AcWing 2868. 子串分值(贡献法)

AcWing 2868. 子串分值 原题链接&#xff1a;https://www.acwing.com/problem/content/2871/ 具体分析过程如下图&#xff1a; 直接遍历的话太麻烦&#xff0c;且时间复杂度太高&#xff0c;所以另寻他路 字符串中只有小写字母26个&#xff0c;所以可以从此着手&#xff0c; …

Netty中的PooledByteBuf池化原理剖析

PooledByteBuf PooledByteBuf是池化的ByteBuf&#xff0c;提高了内存分配与释放的速度&#xff0c;它本身是一个抽象泛型类&#xff0c; 有三个子类:PooledDirectByteBuf、PooledHeapByteBuf、PooledUnsafeDirectByteBuf. Jemalloc算法 Netty的PooledByteBuf采用与jemalloc一…

java在当前项目创建文件

public static void main(String[] arge) throws IOException {File file new File("dade02\\dade");//不存在创建if(!file.exists()){file.mkdirs();}File file1 new File("dade02\\dade\\daade.txt");file1.createNewFile();}或者 public static void …

Rust ?运算符 Rust读写txt文件

一、Rust &#xff1f;运算符 &#xff1f;运算符&#xff1a;传播错误的一种快捷方式。 如果Result是Ok&#xff1a;Ok中的值就是表达式的结果&#xff0c;然后继续执行程序。 如果Result是Err&#xff1a;Err就是整个函数的返回值&#xff0c;就像使用了return &#xff…

租用海外服务器,自己部署ChatGPT-Next-Web,实现ChatGPT聊天自由,还可以分享给朋友用

前言 如果有好几个人需要使用ChatGPT&#xff0c;又没有魔法上网环境&#xff0c;最好就是自己搭建一个海外的服务器环境&#xff0c;然后很多人就可以同时直接用了。 大概是情况是要花80元租一个一年的海外服务器&#xff0c;花15元租一个一年的域名&#xff0c;然后openai 的…

搜索专项---DFS之连通性模型

文章目录 迷宫红与黑 一、迷宫OJ链接 本题思路:DFS直接搜即可。 #include <iostream> #include <cstring> #include <algorithm>constexpr int N110;int n; char g[N][N]; bool st[N][N]; int x1, y1, x2, y2;int dx[4] {-1, 0, 1, 0}, dy[4] {0, 1, 0, …