第十四章 Stream API

JAVA语言引入了一个流式Stream API,这个API对集合数据进行操作,类似于使用SQL执行的数据库查询,同样可以使用Stream API并行执行操作。

Stream和Collection的区别

Collection:静态的内存数据结构,强调的是数据。

Stream API:和集合相关的计算操作,强调的是计算。

Collection面向的是内存,存储在内存中;Stream API面向的是CPU,通过CPU来计算。

Stream API的操作步骤

第一步:创建Stream

通过数据源(如集合、数组等)来获取一个Stream对象。

第二步:中间操作

对数据源的数据进行处理,该操作会返回一个Stream对象,因此可以进行链式操作。

第三步:终止操作

执行终止操作时,才会真正执行中间操作,并返回一个计算完毕后的结果。

Stream API的重要特点

  • Stream自己不会存储元素,只能对元素进行计算.
  • Stream不会改变数据对象,反而可能会返回一个持有结果的新Stream.
  • Stream上的操作属于延迟执行,只有等到用户真正需要结果的时候才会执行.
  • Stream一旦执行了终止操作,则就不能再调用其它中间操作或中止操作了.

顺序流和并行流

        在前面获得Stream对象的方式,我们都称之为“顺序流",顺序流对Stream元素的处理是单线程的,即一个一个元素进行处理,处理数据的效率较低,如果Stream流中的数据处理没有顺序要求,并且还希望可以并行处理Stream的元素,那么就可以使用"并行流"来实现,从而提高处理数据的效率。
一个普通Stream转换为可以并行处理的stream非常简单,只需要用调用Stream提供的parallel()方法进行转换即可,这样就可以并行的处理Stream的元素,不需要编写任何多线程代码就可以享受到并行处理带来的执行效率的提升。

获取Stream的方式 

通过Collection接口的stream()方法来获取Stream对象

public class StreamAPITest01 {public static void main(String[] args) {List<Integer> list = new ArrayList<>();list.add(1);list.add(2);list.add(3);list.add(4);// 注意,这个流属于顺序流,本质是单线程的。数据量如果不是很多,采用这种方式。Stream<Integer> stream = list.stream();// java.util.stream.ReferencePipeline$Head@b4c966a// 通过Stream对象可以对集合中的元素进行计算。System.out.println(stream);     // 输出stream对象的内存地址// 这是一个并行流(底层自动启动多线程,你不需要管,程序员不需要干涉)// 在计算的时候自动会启动多线程去运算。// 什么时候用?如果数据量非常庞大。Stream<Integer> parallelStream = list.parallelStream();// java.util.stream.ReferencePipeline$Head@2f4d3709System.out.println(parallelStream);}
}

通过Arrays数组工具类的stream()方法

public class StreamAPITest02 {public static void main(String[] args) {String[] names = {"zhangsan", "lisi", "wangwu"};Stream<String> stream = Arrays.stream(names);       // 上面集合对应的流对象System.out.println(stream);int[] nums = {1,2,3,4};IntStream stream1 = Arrays.stream(nums);System.out.println(stream1);long[] lnums = {1L,2L,3L};LongStream stream2 = Arrays.stream(lnums);System.out.println(stream2);}
}

使用Stream接口本身的of(可变长度参数)方法

public class StreamAPITest03 {public static void main(String[] args) {// java.util.stream.ReferencePipeline$Head@b4c966a// stream是一个顺序流,单线程Stream<String> stream = Stream.of("abc", "def", "xyz");System.out.println(stream);System.out.println(stream.isParallel()); // falseStream<String> parallel = stream.parallel();    // 将stream对象变为并行流System.out.println(parallel);System.out.println(stream == parallel); // trueSystem.out.println(parallel.isParallel()); // true// java.util.stream.ReferencePipeline$Head@2f4d3709Stream<Integer> integerStream = Stream.of(1, 2, 3, 4);System.out.println(integerStream);}
}

Stream中间操作

Student类

public class Student implements Comparable<Student>{private String name;private int age;private String gender;@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +", gender='" + gender + '\'' +'}';}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 String getGender() {return gender;}public void setGender(String gender) {this.gender = gender;}public Student(String name, int age, String gender) {this.name = name;this.age = age;this.gender = gender;}@Overridepublic boolean equals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;Student student = (Student) o;return age == student.age && Objects.equals(name, student.name) && Objects.equals(gender, student.gender);}@Overridepublic int hashCode() {return Objects.hash(name, age, gender);}@Overridepublic int compareTo(Student o) {return this.getAge() - o.getAge();}
}

StudentService类

public class StudentService {public static List<Student> getStudents(){List<Student> studentList = new ArrayList<>();studentList.add(new Student("zhangsan", 20, "男"));studentList.add(new Student("lisi", 21, "女"));studentList.add(new Student("wangwu", 22, "男"));studentList.add(new Student("zhaoliu", 18, "女"));studentList.add(new Student("qianqi", 19, "女"));/*studentList.add(new Student("qianqi", 19, "男"));studentList.add(new Student("qianqi", 19, "男"));studentList.add(new Student("qianqi", 19, "男"));*/return studentList;}
}

filter(过滤)

public class StreamAPITest04 {public static void main(String[] args) {// 筛选出年龄大于20的学生对象// filter 属于中间操作,过滤// forEach 属于终止操作,遍历// filter和forEach都是Stream接口中的方法。// 由于Stream支持链式调用,所以可以一致"."// 匿名内部类的方式StudentService.getStudents().stream().filter(new Predicate<Student>() {@Overridepublic boolean test(Student student) {return student.getAge() > 20;}}).forEach(new Consumer<Student>() {            // 必须要有终止操作@Overridepublic void accept(Student student) {System.out.println(student);}});// Lambda表达式方式StudentService.getStudents().stream().filter(student -> student.getAge() > 20).forEach(System.out::println);// 筛选出字符串长度大于3的元素Stream<String> stream = Stream.of("zhangsan", "lisi", "wangwu", "abc");stream.filter(s -> s.length() > 3).forEach(System.out::println);// 筛选出学生名字长度大于4的学生StudentService.getStudents().stream().filter(student -> student.getName().length() > 4).forEach(System.out::println);}
}

map(映射)

public class StreamAPITest05 {public static void main(String[] args) {// 把字符串中的字母全部转化为大写// 匿名内部类的方式Stream.of("abc", "def", "xyz").map(new Function<String, String>() {@Overridepublic String apply(String s) {return s.toUpperCase();}}).forEach(System.out::println);// Lambda表达式方式Stream.of("abc", "def", "xyz").map(String::toUpperCase).forEach(System.out::println);// 获得集合中所有学生的名字StudentService.getStudents().stream().map(Student::getName).forEach(System.out::println);System.out.println("==============");// 需求:获得集合中性别为男的学生名字// 思路:先筛选,后映射// 先filter,然后mapStudentService.getStudents().stream().filter(student -> student.getGender().equals("男")).map(Student::getName).forEach(System.out::println);System.out.println("==================");// 将多个集合中的数据合并到一个流Stream当中// flatMap的方法作用是什么?将多个集合中的所有元素全部放到一个Stream中。List<Integer> list1 = new ArrayList<>();list1.add(1);list1.add(2);list1.add(3);List<Integer> list2 = new ArrayList<>();list1.add(4);list1.add(5);list1.add(6);Stream<List<Integer>> twoListStream = Stream.of(list1, list2);// 匿名内部类方式/*twoListStream.flatMap(new Function<List<Integer>, Stream<?>>() {@Overridepublic Stream<?> apply(List<Integer> integers) {return integers.stream();}}).forEach(System.out::println);*/// Lambda表达式方式twoListStream.flatMap(List<Integer>::stream).forEach(System.out::println);}
}

distinct(去重)

public class StreamAPITest06 {public static void main(String[] args) {// 除去重复的元素Stream.of(1,1,1,1,1,1,1,2).distinct().forEach(System.out::println);// 除去重复的学生(除重后输出学生对象)// 去除重复记录是基于 hashCode + equals方法的。记得重写。StudentService.getStudents().stream().distinct().forEach(System.out::println);// 需求:除去年龄相同的学生(除重后输出学生年龄)// 思路:先映射,后除重// 先把学生映射成对应的年龄,然后再去重StudentService.getStudents().stream().map(Student::getAge).distinct().forEach(System.out::println);}
}

sorted(排序)

public class StreamAPITest07 {public static void main(String[] args) {// 需求:对元素执行“升序”排序Stream.of(1,2,3,4,100,0,-1).sorted().forEach(System.out::println);Stream.of("ccc", "bbb", "abc", "aaa").sorted().forEach(System.out::println);    // aaa, abc, bbb, ccc// 需求:按照学生的年龄执行“升序”排序(排序后输出学生对象)// 注意:这里的排序是对学生对象进行排序,排序规则需要指定,Student实现java.lang.Comparable接口。StudentService.getStudents().stream().sorted().forEach(System.out::println);// 需求:按照学生的年龄执行“升序”排序(排序后输出学生年龄)// 先映射,再排序StudentService.getStudents().stream().map(Student::getAge).sorted().forEach(System.out::println);System.out.println("==================");// 需求:对元素执行“升序”排序Stream.of(10, 20, 30, 18, 15).sorted(Integer::compareTo).forEach(System.out::println);// 需求:按照学生的年龄执行“降序”排序(排序后输出学生对象)StudentService.getStudents().stream().sorted((o1,o2) -> o2.getAge() - o1.getAge()).forEach(System.out::println);// 需求:按照学生的年龄执行“升序”排序(排序后输出学生年龄)// 先映射,再排序StudentService.getStudents().stream().map(Student::getAge).sorted().forEach(System.out::println);StudentService.getStudents().stream().map(Student::getAge).sorted(Integer::compareTo).forEach(System.out::println);}
}

concat(合并)

public class StreamAPITest08 {public static void main(String[] args) {Stream<Integer> stream1 = Stream.of(1, 2, 3);Stream<Integer> stream2 = Stream.of(4, 5, 6);Stream.concat(stream1, stream2).forEach(System.out::println);}
}

skip+limit(截取集合的一部分)

public class StreamAPITest09 {public static void main(String[] args) {Stream.of(1,2,3,4,5,6,7,8,9,10).skip(3).limit(3).forEach(System.out::println);  // 4 5 6}
}

match

public class StreamAPITest10 {public static void main(String[] args) {// 匹配集合中元素是否都是3// allMatch 匹配所有System.out.println(Stream.of(1, 2, 3, 4).allMatch(value -> value.equals(3))); // falseSystem.out.println(Stream.of(3, 3, 3, 3).allMatch(value -> value.equals(3))); // true// 匿名内部类System.out.println(Stream.of(3, 3, 3, 3).allMatch(new Predicate<Integer>() {@Overridepublic boolean test(Integer value) {return value.equals(3);}}));// 匹配集合中元素是否包含3// anyMatch 匹配其中一个System.out.println(Stream.of(1, 2, 3, 4).anyMatch(value -> value.equals(3))); // true// 匹配集合中元素有没有3// noneMatch 匹配不上System.out.println(Stream.of(1, 2, 3, 4).noneMatch(value -> value.equals(3))); // falseSystem.out.println(Stream.of(1, 2, 3, 4).noneMatch(value -> value.equals(100))); // true// 获取流中第一个元素Optional<Integer> firstOptional = Stream.of(1, 2, 3, 4).findFirst();System.out.println(firstOptional.get());System.out.println(Stream.of(1, 2, 3, 4).findFirst().get());// 需求:匹配学生名字是否都为“zhangsan”System.out.println(StudentService.getStudents().stream().allMatch(student -> student.getName().equals("zhangsan"))); // false// 需求:匹配学生名字是否至少有一个为“zhangsan”System.out.println(StudentService.getStudents().stream().anyMatch(student -> student.getName().equals("zhangsan"))); // true// 需求:匹配学生名字中是否全部都没有“lucy”System.out.println(StudentService.getStudents().stream().noneMatch(student -> student.getName().equals("lucy"))); // true// 需求:获得第一个学生System.out.println(StudentService.getStudents().stream().findFirst().get());Optional<Student> first = StudentService.getStudents().stream().findFirst();/*if (first.isPresent()) {System.out.println(first.get());}*/first.ifPresent(System.out::println);// 需求:获得第四个学生// 思路:跳过前面3个学生,然后再获得第一个元素System.out.println(StudentService.getStudents().stream().skip(3).findFirst().get());}
}

Stream终止操作(reduce)

作用:将流中的所有数据,按照指定的规则,最终计算出一个结果。

其中预定义的函数式接口是 BinaryOperator

public class StreamAPITest11 {public static void main(String[] args) {// 将集合中的所有数字求和      累加器,初始值为0,也就是当前代码中的  xSystem.out.println(Stream.of(1, 2, 3, 4).reduce((x, y) -> x + y).get());        // 10// 使用数学工具类(方法引用)System.out.println(Math.addExact(10, 20));      // 30System.out.println(Stream.of(1, 2, 3, 4).reduce((x, y) -> Math.addExact(x, y)).get());  // 10System.out.println(Stream.of(1, 2, 3, 4).reduce(Math::addExact).get());// 需求:获得集合中所有元素“相乘”的结果System.out.println(Stream.of(1, 2, 3, 4).reduce(Math::multiplyExact).get());// 需求:获得最大长度的元素System.out.println(Stream.of("abc", "def", "hello", "helloworld").reduce((s1, s2) -> s1.length() > s2.length() ? s1 : s2).get());// 需求:获得所有学生的总年龄System.out.println(StudentService.getStudents().stream().map(Student::getAge).reduce(Math::addExact).get());// 需求:获得10和集合中所有元素“相加”的结果System.out.println(Stream.of(1, 2, 3, 4).reduce(10, Math::addExact));}
}

count,max,min方法

public class StreamAPITest12 {public static void main(String[] args) {// 需求:获得元素的个数System.out.println(StudentService.getStudents().stream().count());System.out.println(StudentService.getStudents().size());// 需求:获得年龄“最大”的学生System.out.println(StudentService.getStudents().stream().max((s1, s2) -> s1.getAge() - s2.getAge()).get());// 需求:获得学生的“最大”年龄System.out.println(StudentService.getStudents().stream().map(Student::getAge).max(Integer::compareTo).get());// 需求:获得年龄“最小”的学生System.out.println(StudentService.getStudents().stream().min((s1, s2) -> s1.getAge() - s2.getAge()).get());// 需求:获得学生的“最小”年龄System.out.println(StudentService.getStudents().stream().map(Student::getAge).min(Integer::compareTo).get());}
}

collect 收集

归集:toList/toSet/toMap

public class StreamAPITest13 {public static void main(String[] args) {// 将流Stream中的数据全部收集到一个集合中。// 收集为List集合。(具体是哪种List集合,在这里是不知道的。)List<String> list = Stream.of("zhangsan", "lisi", "wangwu").collect(Collectors.toList());   // collect传入的参数是收集器System.out.println(list);// 收集为Set集合。(具体是哪种Set集合,在这里是不知道的。)Set<String> set = Stream.of("zhangsan", "lisi", "wangwu", "wangwu").collect(Collectors.toSet());System.out.println(set);// 收集为Map集合。// 匿名内部类的方式/*Map<String, String> map = Stream.of("1:zhangsan", "2:lisi", "3:wangwu").collect(Collectors.toMap(new Function<String, String>() {@Overridepublic String apply(String s) {return s.substring(0, s.indexOf(":"));}}, new Function<String, String>() {@Overridepublic String apply(String s) {return s.substring(s.indexOf(":") + 1);}}));*/// Lambda表达式方式Map<String, String> map = Stream.of("1:zhangsan", "2:lisi", "3:wangwu").collect(Collectors.toMap(s -> s.substring(0, s.indexOf(":")), s -> s.substring(s.indexOf(":") + 1)));// 遍历Map集合map.forEach((k, v) -> System.out.println(k + "===>" + v));}
}

toCollection

以指定的集合类型来进行收集

public class StreamAPITest14 {public static void main(String[] args) {// 注意:ArrayList::new 是构造方法引用// 以ArrayList集合进行收集ArrayList<String> arrayList = Stream.of("zhangsan", "lisi", "wangwu", "wangwu").collect(Collectors.toCollection(ArrayList::new));System.out.println(arrayList);// 以LinkedList集合进行收集LinkedList<String> linkedList = Stream.of("zhangsan", "lisi", "wangwu", "wangwu").collect(Collectors.toCollection(LinkedList::new));System.out.println(linkedList);// 以HashSet集合收集   无序,不可重复HashSet<Integer> hashSet = Stream.of(1, 1, 1, 1, 100, 300, 200, 50, 50).collect(Collectors.toCollection(HashSet::new));System.out.println(hashSet);// 以TreeSet集合收集TreeSet<Integer> treeSet = Stream.of(1, 1, 1, 1, 100, 300, 200, 50, 50).collect(Collectors.toCollection(TreeSet::new));System.out.println(treeSet);}
}
public class StreamAPITest15 {public static void main(String[] args) {ArrayList<Student> students = StudentService.getStudents().stream().filter(student -> student.getGender().equals("女")).filter(student -> student.getAge() > 18).sorted((s1, s2) -> s1.getAge() - s2.getAge()).collect(Collectors.toCollection(ArrayList::new));System.out.println(students);}
}

归集:转换为数组形式

public class StreamAPITest16 {public static void main(String[] args) {// 没有指定数组的类型时,默认转换成Object[]数组。Object[] array = Stream.of(1, 2, 3, 4).toArray();System.out.println(Arrays.toString(array));// 转换为指定类型的数组Integer[] array1 = Stream.of(1, 2, 3, 4).toArray(Integer[]::new);System.out.println(Arrays.toString(array1));String[] array2 = Stream.of("a", "b", "c").toArray(String[]::new);System.out.println(Arrays.toString(array2));        // 字符串数组}
}
public class StreamAPITest17 {public static void main(String[] args) {// 需求:获得元素的个数// 可以使用reducelong count = StudentService.getStudents().stream().count();System.out.println("学生总数:" + count);// 也可以使用collectLong count2 = StudentService.getStudents().stream().collect(Collectors.counting());System.out.println("学生总数:" + count2);// 需求:获得学生的平均年龄Double avgAge = StudentService.getStudents().stream().collect(Collectors.averagingDouble(Student::getAge));System.out.println("学生平均年龄:" + avgAge);// 需求:获得最大年龄的学生Student student = StudentService.getStudents().stream().collect(Collectors.maxBy((s1, s2) -> s1.getAge() - s2.getAge())).get();System.out.println("最大年龄的学生:" + student);//        StudentService.getStudents().stream().max((s1, s2) -> s1.getAge() - s2.getAge()).get();
//        System.out.println("最大年龄的学生02:" + student);// 需求:获得所有学生年龄之和Integer ageSum = StudentService.getStudents().stream().collect(Collectors.summingInt(Student::getAge));System.out.println("所有学生年龄的和:" + ageSum);// 需求:获得年龄的所有的信息DoubleSummaryStatistics collect = StudentService.getStudents().stream().collect(Collectors.summarizingDouble(Student::getAge));System.out.println(collect);System.out.println(collect.getAverage());System.out.println(collect.getMax());System.out.println(collect.getMin());System.out.println(collect.getSum());}
}

分组:groupingBy

public class StreamAPITest18 {public static void main(String[] args) {// 按照性别分组Map<String, List<Student>> map = StudentService.getStudents().stream().collect(Collectors.groupingBy(Student::getGender));map.forEach((k , v) -> System.out.println(k + "===>" + v));}
}

接合:joining

public class StreamAPITest19 {public static void main(String[] args) {// 需求:将所有学生的姓名连接成一个字符串,每个名字之间以“,”连接String s = StudentService.getStudents().stream().map(Student::getName).collect(Collectors.joining(","));System.out.println(s);// 通过 map(Student::getAge) 提取年龄属性       通过 map(String::valueOf) 将整型年龄转为字符串String s1 = StudentService.getStudents().stream().map(Student::getAge).map(String::valueOf).collect(Collectors.joining(","));System.out.println(s1);// 通过 map() 将每个学生对象转换为字符串       再使用 Collectors.toList() 收集为字符串列表List<String> l1 = StudentService.getStudents().stream().map(student->student.getName() + "," + student.getAge()).collect(Collectors.toList());System.out.println(l1);}
}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Oracle数据库各版本间的技术迭代详解

今天我想和大家聊聊一个我们可能每天都在用&#xff0c;但未必真正了解的技术——Oracle数据库的版本。如果你是企业的IT工程师&#xff0c;可能经历过“升级数据库”的头疼&#xff1b;如果你是业务负责人&#xff0c;可能疑惑过“为什么一定要换新版本”&#xff1b;甚至如果…

论文reading学习记录3 - weekly - 模块化视觉端到端ST-P3

文章目录前言一、摘要与引言二、Related Word2.1 可解释的端到端架构2.2 鸟瞰图2.3 未来预测2.4 规划三、方法3.1 感知bev特征积累3.1.1 空间融合&#xff08;帧的对齐&#xff09;3.1.2 时间融合3.2 预测&#xff1a;双路径未来建模3.3 规划&#xff1a;先验知识的整合与提炼4…

crawl4ai--bitcointalk爬虫实战项目

&#x1f4cc; 项目目标本项目旨在自动化抓取 Bitcointalk 论坛中指定板块的帖子数据&#xff08;包括主贴和所有回复&#xff09;&#xff0c;并提取出结构化信息如标题、作者、发帖时间、用户等级、活跃度、Merit 等&#xff0c;以便进一步分析或使用。本项目只供科研学习使用…

调用 System.gc() 的弊端及修复方式

弊端分析不可控的执行时机System.gc() 仅是 建议 JVM 执行垃圾回收&#xff0c;但 JVM 可自由忽略该请求&#xff08;尤其是高负载时&#xff09;。实际回收时机不确定&#xff0c;无法保证内存及时释放。严重的性能问题Stop-The-World 停顿&#xff1a;触发 Full GC 时会暂停所…

git merge 和 git rebase 的区别

主要靠一张图&#xff1a;区别 git merge git checkout feature git merge master此时在feature上git会自动产生一个新的commit 修改的是当前分支 feature。 git rebase git checkout feature git rebase master&#xff08;在feature分支上执行&#xff0c;修改的是master分支…

Java学习--JVM(2)

JVM提供垃圾回收机制&#xff0c;其也是JVM的核心机制&#xff0c;其主要是实现自动回收不再被引用的对象所占用的内存&#xff1b;对内存进行整理&#xff0c;防止内存碎片化&#xff1b;以及对内存分配配进行管理。JVM 通过两种主要算法判断对象是否可回收&#xff1a;引用计…

用大模型(qwen)提取知识三元组并构建可视化知识图谱:从文本到图谱的完整实现

引言 知识图谱作为一种结构化的知识表示方式&#xff0c;在智能问答、推荐系统、数据分析等领域有着广泛应用。在信息爆炸的时代&#xff0c;如何从非结构化文本中提取有价值的知识并进行结构化展示&#xff0c;是NLP领域的重要任务。知识三元组&#xff08;Subject-Relation-O…

(附源码)基于 Go 和 gopacket+Fyne 的跨平台网络抓包工具开发实录

基于 Go 和 gopacket Fyne 的跨平台网络抓包工具开发实录 一、项目背景 在网络安全、协议分析、运维排查等场景中&#xff0c;抓包工具是不可或缺的利器。Wireshark 虽然功能强大&#xff0c;但对于部分初学者或有定制需求的开发者来说&#xff0c;学习曲线较陡&#xff0c;且…

Langchain和Faiss搭建本地知识库对比

对比 对比维度及优缺点分析对比维度LangChain&#xff08;封装 FAISS&#xff09;直接使用 FAISS易用性✅ 高&#xff0c;提供高级封装&#xff0c;简化开发流程❌ 中等&#xff0c;需要熟悉 FAISS API学习成本✅ 低&#xff0c;适合快速开发❌ 高&#xff0c;需要掌握 FAISS 的…

Java常用命令汇总

JDK 工具命令jps&#xff08;Java Virtual Machine Process Status Tool&#xff09;命令示例&#xff1a;jps -l 应用场景&#xff1a;列出当前系统中所有Java进程的PID和主类名&#xff0c;常用于快速定位Java应用的进程ID。javac&#xff08;Java Compiler&#xff09;命令示…

Llama 2:开放基础模型与微调聊天模型

温馨提示&#xff1a; 本篇文章已同步至"AI专题精讲" Llama 2&#xff1a;开放基础模型与微调聊天模型 摘要 在本研究中&#xff0c;我们开发并发布了 Llama 2&#xff0c;一组预训练和微调的大型语言模型&#xff08;LLMs&#xff09;&#xff0c;其规模从 70 亿参…

ThinkPHP 8 在 Apache 下启用伪静态

ThinkPHP 8 在 Apache 下启用伪静态&#xff0c;需要配置 .htaccess 文件并确保 Apache 支持 URL 重写。以下是详细设置步骤&#xff1a;1. 启用 Apache 重写模块首先确保 Apache 的 mod_rewrite 模块已启用。编辑 Apache 配置文件&#xff08;通常是 /etc/apache2/apache2.con…

Android开发中Retrofit使用方法与底层原理详解

Retrofit 是 Android 开发中一个 类型安全、基于注解、高度解耦 的 RESTful HTTP 客户端库&#xff0c;由 Square 公司开发。它极大地简化了 Android 应用与 Web 服务进行网络交互的过程。 核心价值&#xff1a; 声明式 API 定义&#xff1a; 使用 Java/Kotlin 接口和注解描述 …

基于FPGA的IIC控制EEPROM读写(2)

基于FPGA的IIC控制EEPROM读写 文章目录基于FPGA的IIC控制EEPROM读写一、EEPROM简介二、代码实现——个人理解1、状态机2、仿真效果3、上板验证4、代码top.viic_master.vuart三、代码实现——复用性较高的IIC模块1、框架设计2、状态机设计3、仿真效果4、上板验证5、代码top.viic…

C# 界面程序在23H2型号系统中无法退出

20250716记录 环境&#xff1a;c# winform问题描述&#xff1a;主界面退出直接使用了Environment.Exit(0); 程序假死&#xff0c;无法关闭解决措施&#xff1a;//使用 this.Close();以下代码目标&#xff1a;执行完程序自身后&#xff0c;删除指定文件&#xff08;可用于程序文…

Kafka——集群核心参数配置

引言在分布式系统中&#xff0c;Kafka 凭借其高吞吐量、低延迟和强大的扩展性&#xff0c;成为数据管道和流处理的首选解决方案。然而&#xff0c;要充分发挥 Kafka 的性能和稳定性&#xff0c;正确配置集群参数至关重要。为什么参数配置如此重要&#xff1f;Kafka 的参数配置直…

单臂路由实现VLAN互通实验

实验拓扑图实验需求&#xff1a;按照图示为 PC3 和 PC4 配置 IP 地址和网关PC3 属于 Vlan10&#xff0c;PC4 属于 Vlan20&#xff0c;配置单臂路由实现 Vlan10 和 Vlan20 三层互通PC3 和 PC4 可以互通实验步骤&#xff1a;1.PC 配置 IP 地址2.PC3 属于 Vlan10&#xff0c;PC4 属…

基于渐进式迁移学习网络(PTLN)​的小样本故障诊断模型

目录 一、研究背景与挑战​ ​二、创新方法:渐进式迁移学习网络(PTLN)​​ ​1. 核心架构​编辑 ​2. 训练优化​ 三、核心代码 四、实验结果与优势​ ​1. 数据集​ ​2. 性能对比​ ​3. 关键验证​ 五、工程价值与未来方向​ 六、补充信息​ 一、研究背景与挑…

网络原理 —— HTTP

通过网络初识&#xff0c;我们认识了网络的协议栈&#xff0c;TCP/IP 分为五层&#xff1a;应用层&#xff0c;传输层&#xff0c;网络层&#xff0c;数据链路层&#xff0c;物理层。也介绍了其中的关键协议。而这些协议的理解&#xff0c;是我们写网络代码的基础。 应用层&…

docker--安装--原理

安装 链接 启动之后&#xff0c;docker状态查看&#xff1a; sudo systemctl status docker 添加普通用户到docker用户组&#xff1a; sudo usermod -aG docker $USER# 重启或者使用以下命令刷新组权限&#xff1a;newgrp docker 原理