The first time to write a blog, beginners to learn Java, I hope you have a lot of guidance.

Source: Internet
Author: User

Learning about arrays

1. Define an array: int [] list = new int[];

2. When passing an array object to a method, the method can directly modify the contents of the array without having to be implemented by a return value.

Cases:

1  Public Static void incrementall (int[]data) {2for     (int i = 0;i< list.length;i++) {3         data[i]++; 4 }5 }

You can call Incrementall (list) directly;

If you define an array inside a method note (1) There is a return value (2) that does not require an array parameter

1  PublicStsticint[] Buildingarray (intsize) {2     int[]data =New int[size];3      for(inti = 0;i<data.length;i++){4Data[i] = 2*i+1;5 }6                  returndata; 7}

3. Note that the first limitation of the *1* array is that it cannot change its size at run time.

*2* cannot print array contents with a simple print or println method,

*3* cannot use simple = = to compare whether an array is equal.

Method: Arrays.copyof (array,newsize) returns a specified copy with the content set to a value;

Arrays.copyofrange (Array,startindex,endindex) returns a partial copy of the value from the specified array index from STARTINDEX (including) to EndIndex (not included);

Arrays.equals (Array1,array2) returns true if two arrays are equal;

Array.fill (value) sets all elements in the array to the specified value;

Arrays.sort (array) Sorts the contents of the array in ascending order;

Arrays.tostring (array) returns the string representation of the contents of the array;

4. When you print an array, arrays.tostring prints a contiguous string and array.deeptostring prints the array

Accessing an array element with a value less than 0 or greater than the actual length of the array as an index can cause arrayindexoutofboundsexception exceptions.

The first time to write a blog, beginners to learn Java, I hope you have a lot of guidance.

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.