Java——容器(單例集合)(上)

一 容器介紹

  • 容器,是用來容納物體、管理物體。生活中,我們會用到各種各樣的容器。如鍋碗瓢盆、箱子和包等

  • 程序中的“容器”也有類似的功能,用來容納和管理數據。比如,如下新聞網站的新聞列表、教育網站的課程列表就是用“容器”來管理

  • 視頻課程信息也是使用“容器”來管理

  • 計算機當中能夠存儲數據的位置有兩個——>一個是磁盤,一個是內存

    • 磁盤是通過文件的形式存儲數據的——>(永久存儲,不會受到計算機的關閉而影響數據的)
    • 內存是臨時存儲——>關閉計算機后內存中是沒有數據的
    • 容器存儲的數據在內存當中

開發和學習中需要時刻和數據打交道,如何組織這些數據是我們編程中重要的內容。 我們一般通過“容器”來容納和管理數據。事實上,我們前面所學的數組就是一種容器,可以在其中放置對象或基本類型數據。

數組的優勢:是一種簡單的線性序列,可以快速地訪問數組元素,效率高。如果從查詢效率和類型檢查的角度講,數組是最好的。

數組的劣勢:不靈活。容量需要事先定義好,不能隨著需求的變化而擴容。比如:我們在一個用戶管理系統中,要把今天注冊的所有用戶取出來,那么這樣的用戶有多少個?我們在寫程序時是無法確定的。因此,在這里就不能使用數組。

基于數組并不能滿足我們對于“管理和組織數據的需求”,所以我們需要一種更強大、更靈活、容量隨時可擴的容器來裝載我們的對象。 這就是我們今天要學習的容器,也叫集合(Collection)。






二 容器結構

(三大接口)



1 結構圖
在這里插入圖片描述

? List和Set都是單例接口,Map是雙例接口(k,v)



2 單例集合
在這里插入圖片描述

? List——>相當于動態數組,Set——>相當于數學里的集合



3 雙例集合
在這里插入圖片描述

? Map——>相當于數學里的函數,(mapping——>映射)





(單例集合)

三 (*)Collection接口

(12個方法)

(定義了單例集合的基本行為)

(接口中的方法很重要,注意返回值,和返回值類型)

Collection 表示一組對象,它是集中、收集的意思。Collection接口的兩個子接口是List、Set接口。
在這里插入圖片描述
在這里插入圖片描述

Collection接口中定義的方法

方法說明
boolean add(Object element)增加元素到容器中
boolean remove(Object element)從容器中移除元素
boolean contains(Object element)容器中是否包含該元素
int size()容器中元素的數量
boolean isEmpty()容器是否為空
void clear()清空容器中所有元素
Iterator iterator()獲得迭代器,用于遍歷所有元素
boolean containsAll(Collection c)本容器是否包含c容器中的所有元素
boolean addAll(Collection c)將容器c中所有元素增加到本容器
boolean removeAll(Collection c)移除本容器和容器c中都包含的元素
boolean retainAll(Collection c)取本容器和容器c中都包含的元素,移除非交集元素
Object[] toArray()轉化成Object數組

由于List、Set是Collection的子接口,意味著所有List、Set的實現類都有上面的方法。

JDK8之后,Collection接口新增的方法(將在JDK新特性和函數式編程中介紹):

新增方法說明
removeIf作用是刪除容器中所有滿足filter指定條件的元素
stream parallelStreamstream和parallelStream 分別返回該容器的Stream視圖表示,不同之處在于parallelStream()返回并行的Stream,Stream是Java函數式編程的核心類。
spliterator可分割的迭代器,不同以往的iterator需要順序迭代,Spliterator可以分割為若干個小的迭代器進行并行操作,可以實現多線程操作提高效率






四 (*)List接口

(6個方法)

(進一步細化了單例集合的存儲特征)

(有序,可重復)




List接口特點

List是有序、可重復的容器。

有序:有序(元素存入集合的順序和取出的順序一致)。List中每個元素都有索引標記。可以根據元素的索引標記(在List中的位置)訪問元素,從而精確控制這些元素

可重復:List允許加入重復的元素。更確切地講,List通常允許滿足 e1.equals(e2) 的元素重復加入容器。



List接口中的常用方法

除了Collection接口中的方法,List多了一些跟順序(索引)有關的方法,參見下表:

方法說明
void add (int index, Object element)在指定位置插入元素,以前元素全部后移一位
Object set (int index,Object element)修改指定位置的元素
Object get (int index)返回指定位置的元素
Object remove (int index)刪除指定位置的元素,后面元素全部前移一位
int indexOf (Object o)返回第一個匹配元素的索引,如果沒有該元素,返回-1.
int lastIndexOf (Object o)返回最后一個匹配元素的索引,如果沒有該元素,返回-1









五(ArrayList)

1 ArrayList容器的基本操作

(Collection里面的方法——>添加,刪除,轉數組,長度,判空,清除)

(是List接口的實現類。是List存儲特征的具體實現)

(底層是用數組實現的——>查詢效率高,增刪效率低,線程不安全)

(數組是有索引的查詢快,但是插入和刪除都要移動后面所有的數據慢)

(建議如果沒有用到Arraylist里面的方法,最好用List接口類型定義引用)








實例化
在這里插入圖片描述

? 三種定義方式都可以

  • 但是ArrayList繼承了List接口和Collection接口,可以用包括自己的所有的方法(缺點就是以后換容器時候代碼會作廢)
  • 用List雖然方法少,但是以后換容器的時候不用擔心
  • 用Collection定義方法太少,一般不會用

建議如果沒有用到Arraylist里面的方法,最好用List接口類型定義引用

示例

public class ArrayListTest {public static void main(String[] args) {//實例化ArrayList容器List<String> list = new ArrayList<>();//添加元素boolean flag1 = list.add("xiaojia");boolean flag2 = list.add("xiaoliu");boolean flag3 = list.add("jia");boolean flag4 = list.add("jia");System.out.println(flag1+"\t"+flag2+"\t"+flag3+"\t"+flag4);//將ArrayList轉換為數組——>Collextion里面的方法,和數組里面的方法Object[] objects = list.toArray();System.out.println(Arrays.toString(objects));//刪除元素——>可以選擇刪除數據,或者位置boolean flag4 = list.remove("oldlu");System.out.println(flag4);//獲取容器中元素的個數int size = list.size();System.out.println(size);//判斷容器是否為空boolean empty = list.isEmpty();System.out.println(empty);//容器中是否包含指定的元素boolean value = list.contains("itbz");System.out.println(value);//清空容器list.clear();Object[] objects1 = list.toArray();System.out.println(Arrays.toString(objects1));}
}




2 ArrayList容器的索引操作

(6個操作)

(指定位置添加元素,獲取元素,元素替換,刪除指定位置,查找元素在容器(第一次)(最后一次)出現位置)

public class ArrayListTest2 {public static void main(String[] args) {//實例化容器List<String> list = new ArrayList<>();//添加元素list.add("jia");list.add("jiajia");//向指定位置添加元素list.add(0,"xiao");System.out.println("獲取元素");String value1 = list.get(0);System.out.println(value1);System.out.println("獲取所有元素方式一");//使用普通for循環for(int i=0;i<list.size();i++){System.out.println(list.get(i));}System.out.println("獲取所有元素方式二");//使用Foreach循環for(String str:list){System.out.println(str);}System.out.println("元素替換");list.set(1,"kevin");for(String str:list){System.out.println(str);}System.out.println("根據索引位置刪除元素);String value2 = list.remove(1);System.out.println(value2);System.out.println("----------------");for(String str:list){System.out.println(str);}System.out.println("查找元素第一次出現的位置");int value3 = list.indexOf("jjj");System.out.println(value3);System.out.println("查找元素最后一次出現的位置");list.add("jjj");for(String str:list){System.out.println(str);}int value4 = list.lastIndexOf("jjj");System.out.println(value4);}
}




3 ArrayList并集、交集、差集

(Collection里面的3個方法)

(addAll,retainAll,removeAll)

并集

 //并集操作:將另一個容器中的元素添加到當前容器中List<String> a = new ArrayList<>();a.add("a");a.add("b");a.add("c");List<String> b = new ArrayList<>();b.add("a");b.add("b");b.add("c");//a并集ba.addAll(b);for(String str :a){System.out.println(str);}

交集

 //交集操作:保留相同的,刪除不同的List<String> a1 = new ArrayList<>();a1.add("a");a1.add("b");a1.add("c");List<String> b1 = new ArrayList<>();b1.add("a");b1.add("d");b1.add("e");//交集操作a1.retainAll(b1);for(String str :a1){System.out.println(str);}

差集

//差集操作:保留不同的,刪除相同的List<String> a2 = new ArrayList<>();a2.add("a");a2.add("b");a2.add("c");List<String> b2= new ArrayList<>();b2.add("b");b2.add("c");b2.add("d");a2.removeAll(b2);for(String str :a2){System.out.println(str);}





4 ArrayList源碼分析

數組的初始化和擴容——>最開始數組長度為10,然后以1.5倍擴容,jdk1.8之后在操作數組時才初始化,節省內存

1
在這里插入圖片描述

2
在這里插入圖片描述

3
在這里插入圖片描述

4
在這里插入圖片描述







六 (Vector)

1 Vector容器的使用

(方法都加了同步檢查——>“線程安全,效率低”)

(方法就增加了synchronized同步標記——>為了多線程的時候線程安全)

(單線程——>串型,多線程——>并型)

(使用容器的時候如果對線程安全有要求,大部分都使用ArrayList)





Vector(向量)的使用

Vector的使用與ArrayList是相同的,因為他們都實現了List接口,對List接口中的抽象方法做了具體實現。

public class VectorTest {public static void main(String[] args) {//實例化VectorList<String> v = new Vector<>();v.add("a");v.add("b");v.add("a");for(int i=0;i<v.size();i++){System.out.println(v.get(i));}System.out.println("----------------------");for(String str:v){System.out.println(str);}}
}




2 Vector源碼分析

(和ArrayList底層都是數組,區別就是線程安全和效率)

(數組初始化方式,ArrayList1.8之后是延遲初始化(調用時初始化),在Vector中是立即初始化,長度也是10)

(ArrayList數組擴容1.5倍,Vector2倍擴容)

成員變量

/*** The array buffer into which the components of the vector are* stored. The capacity of the vector is the length of this array buffer,* and is at least large enough to contain all the vector's elements.** <p>Any array elements following the last element in the Vector are null.** @serial*/
protected Object[] elementData;/*** The number of valid components in this {@code Vector} object.* Components {@code elementData[0]} through* {@code elementData[elementCount-1]} are the actual items.** @serial*/protected int elementCount;/*** The amount by which the capacity of the vector is automatically* incremented when its size becomes greater than its capacity.  If* the capacity increment is less than or equal to zero, the capacity* of the vector is doubled each time it needs to grow.** @serial*/protected int capacityIncrement;

構造方法

public Vector() {this(10);
}

添加元素

/*** Appends the specified element to the end of this Vector.** @param e element to be appended to this Vector* @return {@code true} (as specified by {@link Collection#add})* @since 1.2*/
public synchronized boolean add(E e) {modCount++;ensureCapacityHelper(elementCount + 1);elementData[elementCount++] = e;return true;
}

數組擴容

/*** This implements the unsynchronized semantics of ensureCapacity.* Synchronized methods in this class can internally call this* method for ensuring capacity without incurring the cost of an* extra synchronization.** @see #ensureCapacity(int)*/
private void ensureCapacityHelper(int minCapacity) {// overflow-conscious code
//判斷是否需要擴容,數組中的元素個數-數組長度,如果大于0表明需要擴容if (minCapacity - elementData.length > 0)grow(minCapacity);
}
private void grow(int minCapacity) {// overflow-conscious codeint oldCapacity = elementData.length;
//擴容2倍int newCapacity = oldCapacity + ((capacityIncrement > 0) ?capacityIncrement : oldCapacity);if (newCapacity - minCapacity < 0)newCapacity = minCapacity;if (newCapacity - MAX_ARRAY_SIZE > 0)newCapacity = hugeCapacity(minCapacity);elementData = Arrays.copyOf(elementData, newCapacity);
}










七 (LinkedList)

1 LinkedList容器介紹

(底層用雙向鏈表實現的存儲——>查詢效率低,增刪效率高,線程不安全)

雙向鏈表也叫雙鏈表,是鏈表的一種,它的每個數據節點中都有兩個指針,分別指向前一個節點和后一個節點。 所以,從雙向鏈表中的任意一個節點開始,都可以很方便地找到所有節點。

每個節點都應該有3部分內容:

class Node<E> {Node<E> previous;   //前一個節點E element;     //本節點保存的數據Node<E> next;        //后一個節點
}

List實現類的選用規則

如何選用ArrayList、LinkedList、Vector?

  1. 需要線程安全時,用Vector。
  2. 不存在線程安全問題時,并且查找較多用ArrayList(一般使用它)
  3. 不存在線程安全問題時,增加或刪除元素較多用LinkedList






2 LinkedList容器的使用

(LinkedList實現了List接口,所以LinkedList是具備List的存儲特征的(有序,元素有重復))

(自己獨有的8個方法)

list標準

public class LinkedListTest {public static void main(String[] args) {//實例化LinkedList容器List<String> list = new LinkedList<>();//添加元素boolean a = list.add("a");boolean b = list.add("b");boolean c = list.add("c");list.add(3,"a");System.out.println(a+"\t"+b+"\t"+c);for(int i=0;i<list.size();i++){System.out.println(list.get(i));}}
}

非list標準——>自己獨有的方法

方法說明
void addFirst(E e)將指定元素插入到開頭
void addLast(E e)將指定元素插入到結尾
getFirst()返回此鏈表的第一個元素
getLast()返回此鏈表的最后一個元素
removeFirst()移除此鏈表中的第一個元素,并返回這個元素
removeLast()移除此鏈表中的最后一個元素,并返回這個元素
E pop()從此鏈表所表示的堆棧處彈出一個元素,等效于removeFirst
void push(E e)將元素推入此鏈表所表示的堆棧 這個等效于addFisrt(E e)
public class LinkedListTest2 {public static void main(String[] args) {System.out.println("-------LinkedList-------------");//將指定元素插入到鏈表開頭LinkedList<String> linkedList1 = new LinkedList<>();linkedList1.addFirst("a");linkedList1.addFirst("b");linkedList1.addFirst("c");for (String str:linkedList1){System.out.println(str);}System.out.println("----------------------");//將指定元素插入到鏈表結尾LinkedList<String> linkedList = new LinkedList<>();linkedList.addLast("a");linkedList.addLast("b");linkedList.addLast("c");for (String str:linkedList){System.out.println(str);}System.out.println("---------------------------");//返回此鏈表的第一個元素System.out.println(linkedList.getFirst());//返回此鏈表的最后一個元素System.out.println(linkedList.getLast());System.out.println("-----------------------");//移除此鏈表中的第一個元素,并返回這個元素linkedList.removeFirst();//移除此鏈表中的最后一個元素,并返回這個元素linkedList.removeLast();for (String str:linkedList){System.out.println(str);}System.out.println("-----------------------");linkedList.addLast("c");//從此鏈表所表示的堆棧處彈出一個元素,等效于removeFirstlinkedList.pop();for (String str:linkedList){System.out.println(str);}System.out.println("-------------------");//將元素推入此鏈表所表示的堆棧  這個等效于addFisrt(E e)linkedList.push("h");for (String str:linkedList){System.out.println(str);}}
}








3 LinkedList源碼分析

1 添加元素

節點類

private static class Node<E> {E item;Node<E> next;Node<E> prev;Node(Node<E> prev, E element, Node<E> next) {this.item = element;this.next = next;this.prev = prev;}
}

成員變量

transient int size = 0;/*** Pointer to first node.* Invariant: (first == null && last == null) ||*       (first.prev == null && first.item != null)*/
transient Node<E> first;/*** Pointer to last node.* Invariant: (first == null && last == null) ||*       (last.next == null && last.item != null)*/
transient Node<E> last;

添加元素

/*** Appends the specified element to the end of this list.** <p>This method is equivalent to {@link #addLast}.** @param e element to be appended to this list* @return {@code true} (as specified by {@link Collection#add})*/
public boolean add(E e) {linkLast(e);return true;
}/*** Links e as last element.*/
void linkLast(E e) {final Node<E> l = last;final Node<E> newNode = new Node<>(l, e, null);last = newNode;if (l == null)first = newNode;elsel.next = newNode;size++;modCount++;
}//創建新節點,頭尾指針指向

2 頭尾添加元素

addFirst

/*** Inserts the specified element at the beginning of this list.** @param e the element to add*/
public void addFirst(E e) {linkFirst(e);
}/*** Links e as first element.*/
private void linkFirst(E e) {final Node<E> f = first;final Node<E> newNode = new Node<>(null, e, f);first = newNode;if (f == null)last = newNode;elsef.prev = newNode;size++;modCount++;
}

addLast

/*** Appends the specified element to the end of this list.** <p>This method is equivalent to {@link #add}.** @param e the element to add*/
public void addLast(E e) {linkLast(e);
}/*** Links e as last element.*/
void linkLast(E e) {final Node<E> l = last;final Node<E> newNode = new Node<>(l, e, null);last = newNode;if (l == null)first = newNode;elsel.next = newNode;size++;modCount++;
}

3 獲取元素——>返回的不是對象是元素

/*** Returns the element at the specified position in this list.** @param index index of the element to return* @return the element at the specified position in this list* @throws IndexOutOfBoundsException {@inheritDoc}*/
public E get(int index) {checkElementIndex(index);return node(index).item;
}
private void checkElementIndex(int index) {if (!isElementIndex(index))throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}
/*** Tells if the argument is the index of an existing element.*/
private boolean isElementIndex(int index) {return index >= 0 && index < size;
}
/*** Returns the (non-null) Node at the specified element index.*/
Node<E> node(int index) {// assert isElementIndex(index);if (index < (size >> 1)) {					//增加查詢效率Node<E> x = first;for (int i = 0; i < index; i++)x = x.next;return x;} else {Node<E> x = last;for (int i = size - 1; i > index; i--)x = x.prev;return x;}
}

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

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

相關文章

word poi-tl 表格功能增強,實現表格功能垂直合并

目錄 問題解決問題poi-tl介紹 功能實現引入依賴模版代碼效果圖 附加&#xff08;插件實現&#xff09;MergeColumnData 對象MergeGroupData 類ServerMergeTableData 數據信息ServerMergeTablePolicy 合并插件 問題 由于在開發功能需求中&#xff0c;word文檔需要垂直合并表格&…

OpenCV相機標定與3D重建(11)機器人世界手眼標定函數calibrateRobotWorldHandEye()的使用

操作系統&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 編程語言&#xff1a;C11 算法描述 計算機器人世界/手眼標定&#xff1a; w T b _{}^{w}\textrm{T}_b w?Tb? 和 c T g _{}^{c}\textrm{T}_g c?Tg?。 cv::calibrateRobotWorldHa…

GPT系列模型簡要概述

GPT-1&#xff1a;&#xff08;0.117B參數量&#xff0c;0.8B words預訓練數據) 動機&#xff1a; 在RNN和Transformer之間&#xff0c;選擇了后者。 和《All your need is Attention》翻譯模型的Encoder-Decoder架構相比&#xff0c;只保留Decoder&#xff0c;因此去掉了Cross…

汽車升級到底應不應該設置“可取消“功能

最近&#xff0c;汽車OTA&#xff08;Over-the-Air&#xff09;升級頻頻成為車主討論的熱點。有些車主反映&#xff0c;一些升級增加了實用功能&#xff0c;而另一些卻讓體驗變得復雜甚至帶來不便。于是&#xff0c;大家不禁發問&#xff1a;汽車升級功能究竟應不應該允許“可取…

單片機 PCB 設計要點

一、引言 單片機作為現代科技的重要組成部分&#xff0c;其 PCB 設計至關重要。本文將詳細介紹單片機 PCB 設計的要點和流程&#xff0c;幫助讀者更好地掌握這一關鍵技術。 在電子世界的浩瀚星海中&#xff0c;單片機無疑是現代科技中一顆閃爍的明珠。作為掌握嵌入式系統的基…

Django+Apscheduler 開發定時任務模塊【六】

目錄 回顧 前五個文章講述了django-autojob的部分代碼和執行邏輯 【DjangoApscheduler 開發定時任務模塊】【一】 【DjangoApscheduler 開發定時任務模塊】【二】 【DjangoApscheduler 開發定時任務模塊】【三】 【DjangoApscheduler 開發定時任務模塊】【四】 【DjangoApsch…

Ubuntu中配置交叉編譯工具的三條命令的詳細研究

關于該把下面的三條交叉編譯配置語句加到哪里&#xff0c;詳情見 https://blog.csdn.net/wenhao_ir/article/details/144326545 的第2點。 現在試解釋下面三條交叉編譯配置語句&#xff1a; export ARCHarm export CROSS_COMPILEarm-buildroot-linux-gnueabihf- export PATH$…

wlanapi.dll丟失怎么辦?有沒有什么靠譜的修復wlanapi.dll方法

在遇到各種系統文件錯誤當中&#xff0c;其中之一就是“wlanapi.dll文件丟失”的問題。這種問題通常發生在Windows操作系統上&#xff0c;特別是當系統試圖執行與無線網絡相關的任務時。wlanapi.dll是一個重要的系統文件&#xff0c;它負責處理Windows無線網絡服務的許多功能。…

利用ipmi工具設置ip、用戶等設置

#打開交互模式 ipmitool -I open shell #切換管理端口為lom1&#xff0c;即共享em1/eth0 delloem lan set shared with lom1 #設置ip、mask、gateway lan set 1 ipaddr 10.0.0.250 lan set 1 netmask 10.0.0.250 lan set 1 defgw ipaddr 10.0.0.250 #查看用戶名 user list 1 …

Python之因子分析詳細步驟

1.數學原理 1.1數學模型 1.2正交因子模型假設 注意&#xff1a;下面的推導都是基于這一假設。因此&#xff0c;這里的模型都是屬于正交因子模型。 1.3正交因子模型的協方差結構 1.4各類方差貢獻的介紹 在1.3正交因子模型的協方差結構中&#xff0c;我們介紹了“方差貢獻”&…

unity3d—demo(2d人物左右移動發射子彈)

目錄 人物代碼示例&#xff1a; 子彈代碼示例&#xff1a; 總結上面代碼&#xff1a; 注意點&#xff1a; 人物代碼示例&#xff1a; using System.Collections; using System.Collections.Generic; using UnityEngine;public class PlayerTiao : MonoBehaviour {public f…

linux之vim

一、模式轉換命令 vim主要有三種模式&#xff1a;命令模式&#xff08;Normal Mode&#xff09;、輸入模式&#xff08;Insert Mode&#xff09;和底線命令模式&#xff08;Command-Line Mode&#xff09;。 從命令模式切換到輸入模式&#xff1a;i&#xff1a;在當前光標所在…

顯存和GPU之間的通信;GPUDirect P2P,NVLink,NCCL;聚合通信和點對點通信

目錄 顯存和GPU之間的分配 顯存和GPU之間的通信 原語是什么,簡單舉例說明 GPUDirect P2P,NVLink,NCCL的全稱及解釋 聚合通信和點對點通信 聚合通信(Collective Communication) 點對點通信(Point-to-Point Communication) 為什么使用GPUDirect P2P,NVLink,NCCL…

Mysql 的 B+ 樹是否包含行數據?

在 MySQL 中&#xff0c;是否在 B樹 的葉子節點上存儲完整的行數據&#xff0c;取決于使用的 存儲引擎 和 索引類型&#xff1a; 聚簇索引 (Clustered Index) 葉子節點包含完整的行數據。 適用場景&#xff1a;MySQL InnoDB 存儲引擎的主鍵索引&#xff08;或聚簇索引&#xf…

【記錄】用JUnit 4的@Test注解時報錯java.lang.NullPointerException的原因與解決方法

項目場景&#xff1a; 在練習黑馬點評的邏輯過期解決緩存擊穿時&#xff0c;編寫了一個預熱緩存數據的單元測試 SpringBootTest public class HmDianPingApplicationTests {Resourceprivate ShopServiceImpl shopService;Testpublic void testSaveShop() throws InterruptedE…

echarts使用整理

4、條形分區統計 <div ref"chartsVal1" class"chartsline-div"></div> const chartsVal1 ref(null); const chartsVal1Title ref(運行時間統計);drewCharts2(chartsVal1, chartsVal1Title.value);function drewCharts2(id, title) {const m…

【八股】HTTP

瀏覽器輸入URL之后發生的過程 瀏覽器解析URL中的協議&#xff0c;主機&#xff0c;端口&#xff0c;路徑參數等DNS域名解析得到對應的IP地址通過IP和PORT對服務器發送TCP三次握手建立連接瀏覽器發送請求服務器接受請求&#xff0c;處理并響應瀏覽器得到HTTP響應&#xff0c;對…

torch.optim.lr_scheduler.ReduceLROnPlateau

torch.optim.lr_scheduler.ReduceLROnPlateau 是 PyTorch 中的一種學習率調度器&#xff0c;主要用于在模型訓練過程中根據某些指標&#xff08;如驗證損失&#xff09;動態調整學習率。它是一種基于性能指標動態調整學習率的策略&#xff0c;而不是預定義的固定時間調整。 主要…

ubuntu下的chattts 學習6:音色固定的學習

魔搭社區 該區提供了隨機種子級音樂的試聽與下載。 spk torch.load(<PT-FILE-PATH>) params_infer_code {spk_emb: spk, } 略 測試過程&#xff1a; 1.先建一個文件夾&#xff1a;然后從上面的網站上下載了兩個。放在里面測試 2 2.測試代碼 import ChatTTS impo…

數據集的重要性:如何構建AIGC訓練集

文章目錄 一、為什么數據集對AIGC如此重要&#xff1f;1. 數據決定模型的知識邊界2. 數據質量直接影響生成效果3. 數據集多樣性提升模型魯棒性 二、構建AIGC訓練集的關鍵步驟1. 明確目標任務和生成需求2. 數據源的選擇3. 數據清洗與預處理4. 數據標注5. 數據增強 三、針對不同類…