JDK8新特性之Steam流

這里寫目錄標題

  • 一、Stream流概述
    • 1.1、傳統寫法
    • 1.2、Stream寫法
    • 1.3、Stream流操作分類
  • 二、Stream流獲取方式
    • 2.1、根據Collection獲取
    • 2.2、通過Stream的of方法
  • 三、Stream常用方法介紹
    • 3.1、forEach
    • 3.2、count
    • 3.3、filter
    • 3.4、limit
    • 3.5、skip
    • 3.6、map
    • 3.7、sorted
    • 3.8、distinct
    • 3.9、match
    • 3.10、find
    • 3.11、max和min
    • 3.12、reduce方法
      • 3.12.1、 map和reduce的組合
    • 3.13、mapToInt
    • 3.14、concat
    • 3.15、綜合案例
    • 4.1、結果收集到集合中
  • 四、Stream結果手集
    • 4.1、結果收集到集合中
    • 4.2、結構收集到數組中
    • 4.3、對流中數據做聚合操作
    • 4.4、對流中數據做分組操作
    • 4.5、對流中數據做分區操作
    • 4.6、對流中數據做拼接
  • 五、并行Stream流
    • 5.1、串行的Stream流
    • 5.2、并行流
      • 5.2.1、獲取并行流
      • 5.2.3、并行流操作
    • 5.3、并行流和串行流對比
    • 5.4、線程安全

一、Stream流概述

Java 中,Stream 是一個來自java.util.stream包的接口,用于對集合(如List、Set等)或數組等數據源進行操作的一種抽象層。
Stream流(和IO流沒有任何關系)主要是對數據進行加工處理的。Stream API能讓我們快速完成許多復雜的操作,如篩選、切片、映射、查找、去除重復,統計,匹配和歸約。

1.1、傳統寫法

現在有需求:對list中姓張,名字長度為3的信息打印:

	public static void main(String[] args) {//定義一個List集合List<String> list = Arrays.asList("張三","張三豐","張無忌","李四","王五");//獲取姓張,名字長度為3的信息,添加到列表中List<String> list1=new ArrayList<>();for (String s : list) {if(s.startsWith("張")&&s.length()==3){list1.add(s);}}for (String s : list1) {System.out.println(s);}}

1.2、Stream寫法

    public static void main(String[] args) {//定義一個List集合List<String> list = Arrays.asList("張三","張三豐","張無忌","李四","王五");list.stream().filter(s -> s.startsWith("張")).filter(s -> s.length()== 3).forEach(System.out::println);}

上面的SteamAPI代碼的含義:獲取流,過濾張,過濾長度,逐一打印。代碼相比于上面的案例更加的簡潔直觀。

1.3、Stream流操作分類

  • 生成操作
    通過數據源(集合、數組等)生成流。
  • 中間操作
    對流進行某種程度的過濾/映射,并返回一個新的流。
  • 終結操作
    執行某個終結操作,一個流只能有一個終結操作。

二、Stream流獲取方式

2.1、根據Collection獲取

java.util.Collection 接口中加入了default方法 stream,也就是說Collection接口下的所有的實現都可以通過steam方法來獲取Stream流。(java集合框架主要包括兩種類型的容器,一種是集合,存儲一個元素集合(Collection),另一種是圖(Map),存儲鍵/值對映射)。

    public static void main(String[] args) {List<String> list=new ArrayList<>();Stream<String> stream=list.stream();Set<String> set=new HashSet<>();Stream<String> stream1=set.stream();Vector vector=new Vector();vector.stream();}

Map接口別沒有實現Collection接口,這時我們可以根據Map獲取對應的key value的集合。

    public static void main(String[] args) {Map<String,Object> map=new HashMap<>();Stream<String> stream=map.keySet().stream();//keyStream<Object> stream1=map.values().stream();//valueStream<Map.Entry<String,Object>> stream2=map.entrySet().stream();//entry}

2.2、通過Stream的of方法

由于數組對象不可能添加默認方法,所有Stream接口中提供了靜態方法of操作到數組中的數據

    public static void main(String[] args) {Stream<String> a1= Stream.of("a1","a2","a3");String[] arr1 = {"aa","bb","cc"};Stream<String> arr11 = Stream.of(arr1);Integer[] arr2 = {1,2,3,4};Stream<Integer> arr21 = Stream.of(arr2);arr21.forEach(System.out::println);// 注意:基本數據類型的數組是不行的int[] arr3 = {1,2,3,4};Stream.of(arr3).forEach(System.out::println);}

三、Stream常用方法介紹

Stream常用方法

方法名方法作用返回值類型防范種類
count統計個數long終結
forEach逐一處理void終結
filter過濾Stream函數拼接
limit取用前幾個Stream函數拼接
skip跳過前幾個Stream函數拼接
map映射Stream函數拼接
concat組合Stream函數拼接
注意:
  1. 這里把常用的API分為“終結方法”和“非終結方法”
  2. “終結方法”:返回值類型不再是 Stream 類型的方法,不再支持鏈式調用。
  3. “非終結方法”:返回值類型仍然是 Stream 類型的方法,支持鏈式調用。
  4. Stream方法返回的是新的流。
  5. Stream不調用終結方法,中間的操作不會執行。

3.1、forEach

forEach用來遍歷流中的數據的。

void forEach(Consumer<? super T> action);

該方法接受一個Consumer接口,會將每一個流元素交給函數處理。

    public static void main(String[] args) {Stream<String> a1=Stream.of("aa","bb","cc");a1.forEach(System.out::println);}

3.2、count

Stream流中的count方法用來統計其中的元素個數的。

  long count();

該方法返回一個long值,代表元素的個數。

    public static void main(String[] args) {long count = Stream.of("a1", "a2", "a3").count();System.out.println(count);}

3.3、filter

filter方法的作用是用來過濾數據的。返回符合條件的數據。
可以通過filter方法將一個流轉換成另一個子集流。

    public static void main(String[] args) {Stream<String> stream =Stream.of("aa", "ab", "bc","a1","b2","c3").filter(s -> s.contains("a"));stream.forEach(System.out::println);}

該接口接收一個Predicate函數式接口參數作為篩選條件。

3.4、limit

limit方法可以對流進行截取處理,支取前n個數據,

  Stream<T> limit(long maxSize);

參數式一個long類型的數值,如果集合當前長度大于參數就進行截取,否則不操作:

      public static void main(String[] args) {Stream.of("a1", "a2", "a3","bb","cc","aa","dd").limit(3).forEach(System.out::println);}

3.5、skip

如果希望跳過前面幾個元素,可以使用skip方法獲取一個截取之后的新流:

  Stream<T> skip(long n);

示例:

    public static void main(String[] args) {Stream.of("a1","b2","c3","aa","bb","cc").skip(3).forEach(System.out::println);}

3.6、map

如果需要將流中的元素映射到另一個流中,可以使用map方法:

  <R> Stream<R> map(Function<? super T, ? extends R> mapper);

該接口需要一個Function函數式接口參數,可以將當前流中的T類型數據轉換為另一種R類型的數據

    public static void main(String[] args) {Stream.of("1","2","3","4","5")//.map(s -> Integer.parseInt(s)).map(Integer::parseInt).forEach(System.out::println);}

3.7、sorted

如果需要將數據排序,可以使用sorted方法:

  Stream<T> sorted();

在使用的時候可以根據自然規則排序,也可以通過比較強來指定對應的排序規則

      public static void main(String[] args) {Stream.of("1","2","7","9","3","4","6").map(Integer::parseInt).sorted((o1, o2) -> (o1 - o2)).forEach(System.out::println);}

3.8、distinct

如果要去掉重復數據,可以使用distinct方法

	Stream<T> distinct();  

Stream流中的distinct方法對于基本數據類型式可以直接去重的,但是對于自定義類型,我們需要重寫hashCode和equals方法來移除重復數據。

    public static void main(String[] args) {Stream.of("1","2","4","5","2","3","4").sorted().distinct().forEach(System.out::println);System.out.println("----------------");Stream.of(new Person("張三",18),new Person("李四",18),new Person("王五",20),new Person("張三",18)).distinct().forEach(System.out::println);}  

3.9、match

如果需要判斷數據是否匹配指定的條件,可以使用match相關的方法:

boolean anyMatch(Predicate<? super T> predicate); // 元素是否有任意一個滿足條件
boolean allMatch(Predicate<? super T> predicate); // 元素是否都滿足條件
boolean noneMatch(Predicate<? super T> predicate); // 元素是否都不滿足條件

使用:

    public static void main(String[] args) {boolean b = Stream.of("1","2","3","4","5","7").map(Integer::parseInt)//.anyMatch(s-> s > 4);//.allMatch(s-> s > 4);.noneMatch(s-> s > 4);System.out.println(b);}  

注:match是一個終結方法。

3.10、find

如果我們需要找到某些數據,可以使用find方法來實現

	Optional<T> findFirst();Optional<T> findAny();

使用:

    public static void main(String[] args) {Optional<String> first = Stream.of("a", "b", "c").findFirst();System.out.println(first.get());Optional<String> any = Stream.of("a", "b", "c","d").findAny();System.out.println(any.get());}

注:

3.11、max和min

如果我們想要獲取最大值和最小值,那么可以使用max和min方法

    public static void main(String[] args) {Optional<Integer> max= Stream.of(1,2,3,4).max(Integer::compareTo);System.out.println(max.get());Optional<Integer> min= Stream.of(1,2,3,4).min(Integer::compareTo);System.out.println(min.get());}  

3.12、reduce方法

如果需要將所有數據歸納得到一個數據,可以使用reduce方法:

    public static void main(String[] args) {Integer sum = Stream.of(4,5,3,7)//identity默認值//第一次的時候會將默認值賦給x//之后每次將上一次的操作結果賦值給x y,就是每次從數據中獲取的元素.reduce(0, (x, y) -> {System.out.println("x="+x+",y="+y);return x + y;});System.out.println("sum = " + sum);// 獲取最大值Integer max = Stream.of(4,5,3,9).reduce(0,(x,y) ->{return x>y?x:y;});System.out.println("max = " + max);}  

3.12.1、 map和reduce的組合

在實際開發中我們經常會將map和reduce一塊來使用:

    public static void main(String[] args) {//1、求出所有年齡總和Integer sumAge= Stream.of(new Person("張三", 20),new Person("李四", 21),new Person("王五", 22),new Person("趙六", 23)).map(Person::getAge).reduce(0,Integer::sum);System.out.println(sumAge);//2、求出所有年齡最大值Integer maxAge= Stream.of(new Person("張三", 20),new Person("李四", 21),new Person("王五", 22),new Person("趙六", 23)).map(Person::getAge).reduce(Integer::max).get();System.out.println(maxAge);//3、統計字符 a 出現的次數Integer countA= Stream.of("a","b","c","d","e","a","a","a").map(ch -> ch.equals("a")?1:0).reduce(0,Integer::sum);System.out.println(countA);}  

3.13、mapToInt

如果需要將Sream中的Integer類型轉換成int類型,可以使用mapToInt方法來實現

    public static void main(String[] args) {//Integer 占用的內存比int多很多,在Stream流操作中會自動裝修和拆箱操作Integer arr[] ={1,2,3,4,6,7,8};Stream.of(arr).filter(x -> x > 0).forEach(System.out::println);//為了提高程序代碼效率,可以先將流中Integer數據轉為為int數據IntStream intStream = Stream.of(arr).mapToInt(Integer::intValue);intStream.forEach(System.out::println);}  

3.14、concat

如果有兩個流,希望合并成為一個流,那么可以使用Stream接口防范concat

    public static void main(String[] args) {Stream<String> steam1=Stream.of("a","b","c");Stream<String> steam2=Stream.of("x","y","z");//通過concat方法將兩個流合并成一個新的流Stream.concat(steam1,steam2).forEach(System.out::println);}  

3.15、綜合案例

4.1、結果收集到集合中

    public static void main(String[] args) {List<String> list1 = Arrays.asList("迪麗熱巴", "宋遠橋", "蘇星河", "老子","莊子", "孫子", "洪七公");List<String> list2 = Arrays.asList("古力娜扎", "張無忌", "張三豐", "趙麗穎","張二狗", "張天愛", "張三");Stream<String> stream1 = list1.stream().filter(s -> s.length() == 3).limit(3);Stream<String> stream2 =list2.stream().filter(s -> s.startsWith("張")).skip(2);Stream.concat(stream1,stream2)//.map(s -> new Person(s)).map(Person::new).forEach(System.out::println);}

四、Stream結果手集

4.1、結果收集到集合中

    @Testpublic void test01(){//收集到list集合中List<String> list= Stream.of("a","b","c").collect(Collectors.toList());System.out.println(list);//收集到set集合中Set<String> set = Stream.of("aa","bb","cc","dd").collect(Collectors.toSet());System.out.println(set);//如果需要獲取的類型為具體實現ArrayList<String> arrayList = Stream.of("aaa","bbb","ccc")//.collect(Collectors.toCollection(() -> new ArrayList<>()));.collect(Collectors.toCollection(ArrayList::new));System.out.println(arrayList);}

4.2、結構收集到數組中

Stream中提供了toArray方法來將結果放到一個數組中,返回值類型是Object[]。
如果我們要指定返回的類型,那么可以使用另一個重載的toArray(IntFunction f)方法。

    @Testpublic void test02(){//收集結果到數組中,數據類型是ObjectObject[] objects = Stream.of("aaa","bbb","ccc").toArray();System.out.println(Arrays.toString(objects));//收集結構到數組中,數據類型是StringString[] strings = Stream.of("aaa","bbb","ccc").toArray(String[]::new);System.out.println(Arrays.toString(strings));}

4.3、對流中數據做聚合操作

當我們使用Stream流處理數據后,可以根據某個屬性將數據分組

    @Testpublic void test03(){//獲取年齡最大值List<Person> personList= Arrays.asList(new Person("張三",20),new Person("李四",25),new Person("王五",30),new Person("趙六",35));Optional<Person> maxAgePerson = personList.stream()//.collect(Collectors.maxBy(Comparator.comparingInt(Person::getAge)));.collect(Collectors.maxBy((p1,p2)->p1.getAge()-p2.getAge()));System.out.println("最大年齡: "+maxAgePerson.get());//獲取年齡最小值Optional<Person> minAgePerson = personList.stream().collect(Collectors.minBy((p1,p2)->p1.getAge()-p2.getAge()));System.out.println("最小年齡: "+minAgePerson.get());//求所有人的年齡之和Integer sumAge = personList.stream().collect(Collectors.summingInt(Person::getAge));System.out.println("年齡總和:" + sumAge);//求所有人的年齡平均值Double avgAge = personList.stream().collect(Collectors.averagingInt(Person::getAge));System.out.println("年齡的平均值:" + avgAge);//統計數量Long count = personList.stream().filter(p-> p.getAge() > 20).collect(Collectors.counting());System.out.println("滿足條件的記錄數:" + count);}

4.4、對流中數據做分組操作

當我們使用Stream流處理數據后,可以根據某個屬性將數據分組

    public void test04(){List<Person> personList= Arrays.asList(new Person("張三", 18, 175), new Person("李四", 22, 177), new Person("張三", 14, 165), new Person("李四", 15, 166), new Person("張三", 19, 182));//根據姓名對數據分組Map<String,List<Person>> map1= personList.stream().collect(Collectors.groupingBy(Person::getName));map1.forEach((k,v)-> System.out.println("k=" + k +"\t"+ "v=" + v));System.out.println("-----------");Map<String, List<Person>> map2 = personList.stream().collect(Collectors.groupingBy(p -> p.getAge() >= 18 ? "成年" : "未成年"));map2.forEach((k,v)-> System.out.println("k=" + k +"\t"+ "v=" + v));}

多級分組

    @Testpublic void test05(){List<Person> personList= Arrays.asList(new Person("張三", 16, 175), new Person("李四", 22, 177), new Person("張三", 14, 165), new Person("李四", 15, 166), new Person("張三", 19, 182));//先根據name分組,然后根據age(成年和未成年)分組Map<String,Map<Object,List<Person>>> map= personList.stream().collect(Collectors.groupingBy(Person::getName,Collectors.groupingBy(p-> p.getAge() >= 18 ? "成年" : "未成年")));map.forEach((k,v)->{System.out.println("k=" + k);v.forEach((kk,vv) -> System.out.println("\t"+"kk="+kk+"\tvv="+vv));});

4.5、對流中數據做分區操作

Collectors.partitioningBy會根據值是否為true,把集合中的數據分割為兩個列表,一個true列表,一個
false列表

    @Testpublic void test06(){List<Person> personList= Arrays.asList(new Person("張三", 16, 175), new Person("李四", 22, 177), new Person("張三", 14, 165), new Person("李四", 15, 166), new Person("張三", 19, 182));Map<Boolean, List<Person>> map = personList.stream().collect(Collectors.partitioningBy(p -> p.getAge() > 18));map.forEach((k,v)-> System.out.println(k+"\t" + v));}

4.6、對流中數據做拼接

Collectors.joining會根據指定的連接符,將所有的元素連接成一個字符串

    @Testpublic void test07(){List<Person> personList= Arrays.asList(new Person("張三", 18, 175), new Person("李四", 22, 177), new Person("張三", 14, 165), new Person("李四", 15, 166), new Person("張三", 19, 182));String s1 = personList.stream().map(Person::getName).collect(Collectors.joining());// 張三李四張三李四張三System.out.println(s1);String s2 = personList.stream().map(Person::getName).collect(Collectors.joining("_"));// 張三_李四_張三_李四_張三System.out.println(s2);String s3 = personList.stream().map(Person::getName).collect(Collectors.joining("_", "###", "$$$"));// ###張三_李四_張三_李四_張三$$$System.out.println(s3);}

五、并行Stream流

5.1、串行的Stream流

我們前面使用的Stream流都是串行,也就是在一個線程上面執行。

    @Testpublic void test01(){long count = Stream.of(5,6,7,4,2,1,9).filter(s ->{System.out.println(Thread.currentThread().getName() + ":" + s);return s > 3;}).count();System.out.println(count);}

5.2、并行流

parallelStream其實就是一個并行執行的流,它通過默認的ForkJoinPool,可以提高多線程任務的速
度。

5.2.1、獲取并行流

    @Testpublic void test02(){List<Integer> list=new ArrayList<>();//通過list接口直接獲取并行流Stream<Integer> stram=list.parallelStream();//將已有的串行流轉換為并行流Stream<Integer> parallel=Stream.of(1,2,3).parallel();}

5.2.3、并行流操作

    @Testpublic void test03(){long count = Stream.of(5,6,7,4,2,1,9).parallel().filter(s ->{System.out.println(Thread.currentThread().getName() + ":" + s);return s > 3;}).count();System.out.println(count);}

5.3、并行流和串行流對比

我們通過for循環,串行Stream流,并行Stream流來對500000000億個數字求和。來看消耗時間

public class StresmTest24 {private static long times=500000000;private long start;@Beforepublic void before(){start=System.currentTimeMillis();}@Afterpublic void end(){long end=System.currentTimeMillis();System.out.println("消耗時間:"+(end - start));}@Testpublic void test01(){System.out.println("普通for循壞:");long res= 0;for (int i = 0;i<times;i++){res+=1;}}@Testpublic void test02(){System.out.println("串行流:serialStream");LongStream.rangeClosed(0,times).reduce(0,Long::sum);}@Testpublic void test03(){LongStream.rangeClosed(0,times).parallel().reduce(0,Long::sum);}}

5.4、線程安全

在多線程的處理下,肯定會出現數據安全問題。如下:

    @Testpublic void test01(){List<Integer> list = new ArrayList<>();for (int i = 0; i < 1000; i++) {list.add(i);}System.out.println(list.size());List<Integer> listNew =new ArrayList<>();list.parallelStream().forEach(listNew::add);System.out.println(listNew.size());}

這個會拋出異常

	java.lang.ArrayIndexOutOfBoundsException

針對這個問題,我們的解決方案有哪些呢?

  1. 加同步鎖
  2. 使用線程安全的容器
  3. 通過Stream中的toArray/collect操作
    實現:
@Testpublic void test02(){List<Integer> listNew = new ArrayList<>();Object obj = new Object();IntStream.rangeClosed(1,1000).parallel().forEach(i->{synchronized (obj){listNew.add(i);}});System.out.println(listNew.size());}@Testpublic void test03(){Vector v = new Vector();Object obj = new Object();IntStream.rangeClosed(1,1000).parallel().forEach(i->{synchronized (obj){v.add(i);}});System.out.println(v.size());}@Testpublic void test04(){List<Integer> listNew = new ArrayList<>();// 將線程不安全的容器包裝為線程安全的容器List<Integer> synchronizedList = Collections.synchronizedList(listNew);Object obj = new Object();IntStream.rangeClosed(1,1000).parallel().forEach(i->{synchronizedList.add(i);});System.out.println(synchronizedList.size());}@Testpublic void test05(){List<Integer> listNew = new ArrayList<>();Object obj = new Object();List<Integer> list = IntStream.rangeClosed(1, 1000).parallel().boxed().collect(Collectors.toList());System.out.println(list.size());}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/82963.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/82963.shtml
英文地址,請注明出處:http://en.pswp.cn/web/82963.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

split方法

在編程中&#xff0c;split 方法通常用于將字符串按照指定的分隔符拆分成多個部分&#xff0c;并返回一個包含拆分結果的列表&#xff08;或數組&#xff09;。不同編程語言中的 split 方法語法略有不同&#xff0c;但核心功能相似。以下是常見語言中的用法&#xff1a; ?1. P…

深入理解 x86 匯編中的符號擴展指令:從 CBW 到 CDQ 的全解析

引入 在匯編語言的世界里&#xff0c;數據寬度的轉換是一項基礎卻至關重要的操作。尤其是在處理有符號數時&#xff0c;符號擴展&#xff08;Sign Extension&#xff09;作為保持數值符號一致性的核心技術&#xff0c;直接影響著運算結果的正確性。本文將聚焦 x86 架構中最常用…

計算機基礎知識(第五篇)

計算機基礎知識&#xff08;第五篇&#xff09; 架構演化與維護 軟件架構的演化和定義 軟件架構的演化和維護就是對架構進行修改和完善的過程&#xff0c;目的就是為了使軟件能夠適應環境的變化而進行的糾錯性修改和完善性修改等&#xff0c;是一個不斷迭代的過程&#xff0…

前端開發三劍客:HTML5+CSS3+ES6

在前端開發領域&#xff0c;HTML、CSS和JavaScript構成了構建網頁與Web應用的核心基礎。隨著技術標準的不斷演進&#xff0c;HTML5、CSS3以及ES6&#xff08;ECMAScript 2015及后續版本&#xff09;帶來了諸多新特性與語法優化&#xff0c;極大地提升了開發效率和用戶體驗。本文…

c++ 頭文件

目錄 防止頭文件重復包含 頭文件的作用 如何讓程序的多個 .cpp 文件之間共享全局變量&#xff08;可能是 int、結構體、數組、指針、類對象&#xff09;? 防止頭文件重復包含 為什么要防止頭問件重復包含&#xff1f; 當然一般也不會把變量定義放到頭問件&#xff0c;那為…

深入解析 JavaScript 中 var、let、const 的核心區別與實踐應用

一、歷史背景與語法基礎 JavaScript 作為動態弱類型語言&#xff0c;變量聲明機制經歷了從 ES5 到 ES6 的重大變革。在 ES5 及更早版本中&#xff0c;var 是唯一的變量聲明方式&#xff0c;而 ES6&#xff08;2015 年&#xff09;引入了 let 和 const&#xff0c;旨在解決 var…

【Linux庖丁解牛】—自定義shell的編寫!

1. 打印命令行提示符 在我們使用系統提供的shell時&#xff0c;每次都會打印出一行字符串&#xff0c;這其實就是命令行提示符&#xff0c;那我們自定義的shell當然也需要這一行字符串。 這一行字符串包含用戶名&#xff0c;主機名&#xff0c;當前工作路徑&#xff0c;所以&a…

應用案例 | 設備分布廣, 現場維護難? 宏集Cogent DataHub助力分布式鍋爐遠程運維, 讓現場變“透明”

在日本&#xff0c;能源利用與環保問題再次成為社會關注的焦點。越來越多的工業用戶開始尋求更高效、可持續的方式來運營設備、管理能源。而作為一家專注于節能與自動化系統集成的企業&#xff0c;日本大阪的TESS工程公司給出了一個值得借鑒的答案。 01 鍋爐遠程監控難題如何破…

【OSG學習筆記】Day 16: 骨骼動畫與蒙皮(osgAnimation)

骨骼動畫基礎 骨骼動畫是 3D 計算機圖形中常用的技術&#xff0c;它通過以下兩個主要組件實現角色動畫。 骨骼系統 (Skeleton)&#xff1a;由層級結構的骨頭組成&#xff0c;類似于人體骨骼蒙皮 (Mesh Skinning)&#xff1a;將模型網格頂點綁定到骨骼上&#xff0c;使骨骼移動…

jdk同時安裝多個版本并自由切換

一、安裝不同版本的JDK 二、配置環境變量&#xff08;多版本JDK&#xff09; 1. 新建版本專用環境變量&#xff08;用于切換&#xff09; 操作位置&#xff1a;系統變量 > 新建 變量名&#xff1a;JAVA_HOME_1.8 變量值&#xff1a;JDK 8安裝路徑變量名&#xff1a;JAVA1…

java中裝飾模式

目錄 一 裝飾模式案例說明 1.1 說明 1.2 代碼 1.2.1 定義數據服務接口 1.2.2 定義基礎數據庫服務實現 1.2.3 日志裝飾器 1.2.4 緩存裝飾器 1.2.5 主程序調用 1.3 裝飾模式的特點 一 裝飾模式案例說明 1.1 說明 本案例是&#xff1a;數據查詢增加緩存&#xff0c;使用…

【論文閱讀】YOLOv8在單目下視多車目標檢測中的應用

Application of YOLOv8 in monocular downward multiple Car Target detection????? 原文真離譜&#xff0c;文章都不全還發上來 引言 自動駕駛技術是21世紀最重要的技術發展之一&#xff0c;有望徹底改變交通安全和效率。任何自動駕駛系統的核心都依賴于通過精確物體檢…

在uni-app中如何從Options API遷移到Composition API?

uni-app 從 Options API 遷移到 Composition API 的詳細指南 一、遷移前的準備 升級環境&#xff1a; 確保 HBuilderX 版本 ≥ 3.2.0項目 uni-app 版本 ≥ 3.0.0 了解 Composition API 基礎&#xff1a; 響應式系統&#xff1a;ref、reactive生命周期鉤子&#xff1a;onMount…

408第一季 - 數據結構 - 圖

圖的概念 完全圖 無向圖的完全圖可以這么想&#xff1a;如果有4個點&#xff0c;每個點都會連向3個點&#xff0c;每個點也都會有來回的邊&#xff0c;所以除以2 有向圖就不用除以2 連通分量 不多解釋 極大連通子圖的意思就是讓你把所有連起來的都圈出來 強連通圖和強連通…

31.2linux中Regmap的API驅動icm20608實驗(編程)_csdn

regmap 框架就講解就是上一個文章&#xff0c;接下來學習編寫的 icm20608 驅動改為 regmap 框架。 icm20608 驅動我們在之前的文章就已經編寫了&#xff01; 因為之前已經對icm20608的設備樹進行了修改&#xff0c;所以大家可以看到之前的文章&#xff01;當然這里我們還是帶領…

Vue速查手冊

Vue速查手冊 CSS deep用法 使用父class進行限定&#xff0c;控制影響范圍&#xff1a; <template><el-input class"my-input" /> </template><style scoped> /* Vue 3 推薦寫法 */ .my-input :deep(.el-input__inner) {background-color…

振動力學:無阻尼多自由度系統(受迫振動)

本文從頻域分析和時域分析揭示系統的運動特性&#xff0c;并給出系統在一般形式激勵下的響應。主要討論如下問題&#xff1a;頻域分析、頻響函數矩陣、反共振、振型疊加法等。 根據文章1中的式(1.7)&#xff0c;可知無阻尼受迫振動的初值問題為&#xff1a; M u ( t ) K u …

真實案例分享,Augment Code和Cursor那個比較好用?

你有沒有遇到過這種情況&#xff1f;明明知道自己想要什么&#xff0c;寫出來的提示詞卻讓AI完全理解錯了。 讓AI翻譯一篇文章&#xff0c;結果生成的中文不倫不類&#xff0c;機器僵硬&#xff0c;詞匯不同&#xff0c;雞同鴨講。中國人看不懂&#xff0c;美國人表示聳肩。就…

zotero及其插件安裝

zotero官網&#xff1a;Zotero | Your personal research assistant zotero中文社區&#xff1a;快速開始 | Zotero 中文社區 插件下載鏡像地址&#xff1a;Zotero 插件商店 | Zotero 中文社區 翻譯&#xff1a;Translate for Zotero 接入騰訊翻譯API&#xff1a;總覽 - 控制…

【SSM】SpringMVC學習筆記8:攔截器

這篇學習筆記是Spring系列筆記的第8篇&#xff0c;該筆記是筆者在學習黑馬程序員SSM框架教程課程期間的筆記&#xff0c;供自己和他人參考。 Spring學習筆記目錄 筆記1&#xff1a;【SSM】Spring基礎&#xff1a; IoC配置學習筆記-CSDN博客 對應黑馬課程P1~P20的內容。 筆記2…