Java Getting Started Basics-array knowledge point finishing __java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.