數(shù)組
- 數(shù)組碩果僅存的優(yōu)點就是效率.
- 新生成一個數(shù)組對象時,其中所有的引用被自動初始化為null,所以檢查其中的引用是否為null,即可知道數(shù)組的某個位置是否存有對象.同樣基本類型的數(shù)組如果是數(shù)值型的,就被自動初始化為0,如果時字符型(char)的,就被自動初始化為(char)0;如果是布爾值(boolean),就被自動初始化為false.
- Arrays.deepToString()方法,它可以將多維素組轉(zhuǎn)換為多個String.它對基本類型數(shù)組和對象數(shù)組都起作用.
- System.arraycopy()
- public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)
Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array referenced by src to the destination array referenced by dest. The number of components copied is equal to the length argument. The components at positions srcPos through srcPos+length-1 in the source array are copied into positions destPos through destPos+length-1, respectively, of the destination array.
Parameters:
src - the source array.
srcPos - starting position in the source array.
dest - the destination array.
destPos - starting position in the destination data.
length - the number of array elements to be copied.
動態(tài)初始化:
- 數(shù)據(jù)類型[] 數(shù)組名 = new 數(shù)據(jù)類型[長度];
- 數(shù)據(jù)類型:--->決定了數(shù)組能夠存放什么樣的數(shù)據(jù)
- [] :---->代表是一個數(shù)組
- 數(shù)組名 :--->為數(shù)組起的名字,為了找到數(shù)組
- new:---> 向堆內(nèi)存申請空間的關鍵字
- 長度: --->數(shù)組中能夠存放多少個數(shù)據(jù)
- 特點: 我們程序員給定長度,由系統(tǒng)給定默認值!!!
靜態(tài)初始化:
完整的格式: 數(shù)據(jù)類型[] 數(shù)組名 = new 數(shù)據(jù)類型[不能寫長度!!!!]{元素1,元素2...};
省略的格式:
數(shù)據(jù)類型[] 數(shù)組名 = {元素1,元素2...};
內(nèi)存劃分
*棧
1. 存放局部變量 ----> 定義在方法里面,或者方法聲明上(參數(shù)列表)的變量都是局部變量
2. 所有的方法都在棧里面運行
3. 堆:
4. 作用:存放new出來的東西
5. 特點:1.都有地址值2.都有默認值整數(shù): 0 小數(shù):0.0 字符:'\u0000 布爾:false 引用數(shù)據(jù)類型:null
方法區(qū)
- 存放字節(jié)碼對象.class相關的信息
- 存放靜態(tài)相關的東西static
- 本地方法棧 ---->系統(tǒng)相同
- 寄存器 --->cpu
獲取數(shù)組的長度
格式:數(shù)組名.length