On the first day of work today, I also learn Java basics. Now I've sorted out the notes in the process of learning arrays.
1, Java, where the data is stored. Below is the screenshot in the video, very clear.
From the above JVM memory allocation diagram, I can also decompose the program into: Data + code (method) +cpu time slice.
Stack stack data can be accessed directly, heap heap is required addressing access, so stack stacks are more efficient than heap.
2, the declaration of an array, refers to the creation of a reference handle space in the stack; The array is also an object that needs to be created using new.
Note: (1) int[] tmp; Then Tmp=null, not 0.
(2) An array can be initialized when it is declared, and an array created with the New keyword must specify the size of the array.
such as: string[] STRs = {"1", "Mrs", "Wang"};//create an array with three elements
int[] tmp = new int[5];//creates an empty array of 5 elements with an element of 0
Int[] Tmp=new int[]{1,5,3};//creates an array of 3 elements
To create an array:
Memory allocation:
Creating an array of objects
Object Array memory allocation:
3, two-dimensional array creation
int[][] arr = new int[5][];//correct
int[][] arr = new int[][5];//error
4, the replication of the array
System.arrarcopy (Object src,int srcpos,object dest,int destpos,int length);//jdk methods used by older versions
Arrays.copyof (t[] original,int newlength) with Arrays.copyofrange (t[) orignal,int from,int to);//This is the way that JDK1.6 started using