- The array can be seen as a combination of a plurality of the same type of data, the unified management of these data.
- Array variable is a reference type, can also be seen as an array of objects, each element in the array corresponds to a member variable of the object.
- Elements in the array may be any type of data, including basic and reference types.
One-dimensional array declaration ways:
Type was []; 或 type [] was;
E.g:
int a1 [] ; int [] a2;
double b [];
Person [] p1;
String s1 [];
Java language does not specify the length declared in the array, for example:
int a [5]; // illicit
Array name = [number of array elements] The new type of array elements
|
package com.nyist; public class TestArray { public static void main(String[] args) { int[] s; s = new int[5]; for(int i=0;i<5;i++) { s[i]=2*i+1; } } } |
ps: In addition to the basic types, all other reference types in Java (reference types are additionally allocated space) |
|