第十四章 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
英文地址,請注明出處:http://en.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 原理