JAVA study notes 01-basic grammar

Array

1. Dynamic initialization
When creating an array, directly specify the number of elements in the array.
Syntax:
data type [] array name = new data type [array length];

int[] array = new int[100];

2. Static initialization
When creating an array, do not directly specify the number of data, but directly specify the specific data content.
Syntax:
data type [] array name = new data type [array length] {array content};

int[] array = new int[]{
    
    1,2,3,4,5};

3. Format omitted

int[] array = {
    
    1,23};

Note:
1. Static initialization does not directly specify the length, but the length will still be automatically calculated
. 2. The standard format of static initialization can be split into two steps
3. Dynamic initialization can also be split into two steps
4. Static initialization once used Omit the format, it cannot be split into two steps

4. Array is passed as a parameter/return value
Declaration:

public static void function(int[] array);

transfer:

function(array1);
public static int[] function();

Guess you like

Origin blog.csdn.net/qq_44708714/article/details/106756959