Java Basics-Array examples & two-dimensional arrays

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

Examples of arrays:

Example 1:
Request an array of string strings and take out the data inside.
Apply a string string first, then enter the value you want to store at the innermost, use the For loop to request that the variable i,i is less than the length of the string array (. length), and then print the first value of the string array to remove the array.

Example 2:
You can also modify the 3rd value of string, since the array starts with 0, so str[2]= "Java";

Example 3:
can apply for a constant array, and modify the value inside, no error.
Final is a constant, and the constant is not assignable. Final control is str this constant name can not be assigned value, nor lock inside the memory, does not mean that the inside of the array can not be assigned value, and will not error.

Example 4:
To apply a char array, the char array is a single-symbol array and prints the value of the char array inside.

Why is the base data type not a string string type?
There is no string string in the base data type that is normal because the string belongs to one type of merge. In fact, the string is to take a char array, in fact, is a combination of char type.

Char array:
The JDK version before 1.8 string string is an array of type char.
1.9 Later versions of JDK use an array of type Byte.
Because the English alphabet can be stored with the byte type, it is sufficient that the previous char type stores English characters as a waste of resources, and the use of byte type storage can save and optimize resources.

Arrays class:
The tool class in the array, specifically for array operations.
You can use arrays to sort the array.

To print array content without looping:

Array sorting process:
Sorting is a comparison of the process, such as the following a string of arrays, it will compare 4 with 3, Judge 4 is 3 who big who small, for granted 3:4 small, then he will put 3 to 1th.
Then it will ask 4 and 2 who is big who small, 2:4 small 2 to the front row, then ask 2 and 3 who big who small, 2:3 small 2 ranked in the front. With this analogy, first find the smallest and then find the 2nd small.

For Loop advanced: It is just a for-loop shorthand, it is not possible to control the subscript number, only can take the value.
for arrays and collections
All the values are taken out, it's just a simple notation.
Compiled into a class file is the same as the previous cyclic notation, did not become, just changed the code of the writing format.

for (Arrays and collections are taken out of what is said to write what type variable name: array or set variable) {};

Two-dimensional arrays: arrays in arrays (multidimensional arrays)
A one-dimensional array is a class: A column consists of
A two-dimensional array is a table: there are rows and columns

Storage structure: Arrays in arrays are two-bit arrays (multidimensional arrays)

Code structure:

Assignment value:
There are 3 ways to assign values:
1. Use the initial values to set the rows and columns.
2. Direct Application
3. The row is not fixed, we can reassign the column

The first type:

The 2nd type:

The 3rd type:

Value:

Loop value:
The length of the row in the two-bit array is first taken, and a loop is nested to calculate the value inside the row.

Java Basics-Array examples & two-dimensional arrays

Related Article

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.