基礎:如何有效的複製和合並陣列
陣列操作快,很多人喜歡用,但陣列是定長的,難以動態擴充套件,一般用合併陣列的辦法。使用clone比較好實現陣列複製:
英文:
It is ok to use clone() for arrays. In the case of arrays that are not of
primitive types, It does a "shallow:" copy meaning it doesn't copy the
objects that are referenced in the array. This is important in the case of
multi-dimensioned arrays. Because they also are just arrays of objects, the
sub-arrays don't get copied.
Use clone() only when you want to create an exact copy of the array, i.e.
same size, same element type.
System.arraycopy works on two existing arrays, so if you use that, you have
to create an empty array first. You would use it if you wanted to copy the
contents of an array to a bigger array (thereby "growing" the array) or if
you want to create an array where the element type is assignment-compatible
with the original array (e.g. going from String[] to Object[]). You can also
use it to move array elements within an array.
英文:
It is ok to use clone() for arrays. In the case of arrays that are not of
primitive types, It does a "shallow:" copy meaning it doesn't copy the
objects that are referenced in the array. This is important in the case of
multi-dimensioned arrays. Because they also are just arrays of objects, the
sub-arrays don't get copied.
Use clone() only when you want to create an exact copy of the array, i.e.
same size, same element type.
System.arraycopy works on two existing arrays, so if you use that, you have
to create an empty array first. You would use it if you wanted to copy the
contents of an array to a bigger array (thereby "growing" the array) or if
you want to create an array where the element type is assignment-compatible
with the original array (e.g. going from String[] to Object[]). You can also
use it to move array elements within an array.
相關文章
- js如何複製指定的陣列JS陣列
- javascript如何複製一個陣列JavaScript陣列
- javascript 陣列的深度複製JavaScript陣列
- C# 陣列的複製C#陣列
- [分享]javascript 陣列以及物件的深拷貝(複製陣列或複製物件)的方法JavaScript陣列物件
- 【基礎題】【陣列】定義並初始化陣列
- JS 複製陣列和物件JS陣列物件
- C#中複製陣列C#陣列
- JS中的陣列複製問題JS陣列
- mysql複製基礎MySql
- JavaSE基礎:陣列Java陣列
- [shell基礎]——陣列陣列
- 陣列基礎使用陣列
- golang基礎之陣列Golang陣列
- 樹狀陣列基礎陣列
- JavaScript基礎——使用陣列JavaScript陣列
- JavaScript基礎(五)陣列JavaScript陣列
- javascript基礎(陣列)(十九)JavaScript陣列
- js如何合併兩個陣列並且刪除重複的元素JS陣列
- 陣列(引用型別)複製問題陣列型別
- C# unsafe 快速複製陣列C#陣列
- javascript陣列如何判斷是否有重複的陣列項JavaScript陣列
- java語言複製陣列的四種方法Java陣列
- js 基礎加固之複製JS
- NumPy 基礎 (一) - 建立陣列陣列
- JAVA基礎--二維陣列Java陣列
- NumPy 陣列複製與檢視詳解陣列
- java函式陣列引數的複製問題Java函式陣列
- 將一個陣列複製到另一個陣列上陣列
- 如何有效的刪除陣列中符合條件的值?陣列
- 如何去除有序陣列中的重複元素陣列
- C#高效能陣列複製實驗C#陣列
- Vue實現對陣列、物件的深拷貝、複製Vue陣列物件
- NumPy 基礎 (二) - 陣列運算陣列
- Go 基礎教程--6 陣列 ArrayGo陣列
- Go 基礎教程--5 陣列 ArrayGo陣列
- 【重溫基礎】10.陣列陣列
- java基礎(十) 陣列型別Java陣列型別