java from entry to the buried (six)

Learning java from entry basis, Azhu lead us today formally entered the sixth study

Past Featured

java from entry to the buried (a)
java from entry to the buried (b)
java from entry to the buried (c)
java from entry to the buried (four)
java from entry to the buried (V)

This issue succinctly and contents of the array
array

Concept : the array is a container that can store a plurality of data values simultaneously

Features :
 1. An array is a type of data referenced by
 a plurality of data out of the array 2, must use the same
 length of the array 3 may not be changed during the program run

Initialize the array
to create an array in memory of them, and give some default values to which

Common initialized:
 the number 1. Dynamic initialization (specified length), which specify an array of data elements directly in love when you create the array
 2. Static Initialization (specify the content), in the creation of the array, the data does not directly specify a how much the number, but directly to the specific data content directly specified

Dynamic format array initialization
data type array [] = new data type names (array length);
Here Insert Picture Description
parsing Meaning:
1. The left data type is stored in the data array, are all unified what type
2. On the left in brackets is representative of an array of I
3 left array name, a name to an array
4. new right represents the operation of creating an array
5. the right-side data types, data types must be consistent and left
6 right the length of the brackets, which is an array, in the end how much data can be stored, is a digital int

NOTE: When using dynamic initialize an array, wherein the elements will automatically have a default value, the following rules:
1. If the integer type, the default is 0;
2. floating type, the default is 0.0;
3. character, default '\ u0000 ';
4. reference type, default null;

Static standard format:
Data Type [] array name Data type [] = new elements {1, element 2, ...}

Omitted Format:
data type array [] = {Title element 1, element 2, ...}
Here Insert Picture Description
Note:
1. The length of the static initialization is not directly specified, but is automatically calculated to obtain the length of
two static initialization step 2. The standard format may be analyzed
3 dynamic initialization can also be called a two-step analysis

java memory need to be divided :
Here Insert Picture Description

An array of memory map:

Here Insert Picture Description
FIG two arrays of memory:
Here Insert Picture Description

Index
index number from 0 array, consistent with the "-1 until the length of the array"

(1) If the access time of the array elements, index number does not exist, it will happen array index out of bounds abnormal
reasons: wrong index number
Solution: Modify become correct index number exists

All reference type variable can be assigned a null value, but on behalf of which have nothing
array must be new initialized to use its elements
(2) if only given a null, no new creation
abnormal null pointer occurs
reasons: forget the new
resolve: to make up new
Here Insert Picture Description
length
how to obtain the length of the array
format: array name .length
will get an int number, represents the length of the array Here Insert Picture Description
method

Array as a parameter method
When you call the method when parentheses are passed to the method, passing into the address value is actually an array ofHere Insert Picture Description
Note: 0,1 method can have a plurality of parameters, but only the return value of 0 or 1, can not have multiple return values

If you want a method to produce a number of results returned data is how to do?
Method: using an array type as the return value to

Any data type can be used as a method of parameter types, the return type, or

Array as a parameter of the method, in fact, passed into the array address value
array as the return value, the return value is actually the address of the arrayHere Insert Picture Description

Well, this concludes the array
like to
      
point out errors

+ Thumbs attention

Published 18 original articles · won praise 79 · views 20000 +

Guess you like

Origin blog.csdn.net/m0_46315852/article/details/105035123