Array (array), Array array
1. Array: a set of data of the same type is called an Array.
2. array definition and value assignment (the system will initialize it by default)
Normal Array:
1 package com. li; 2 3 public class Array {4 5 public static void main (String [] args) {6 // Methods automatically generated by TODO, for example, 7 int [] a = new int [2]; 8 9/* 10 * int a [] = new int [2]; 11 * int [] a = {0, 1}; 12 * int [] a = new int [] {0, 1 }; // type [] variable name = {new type []} {list of initialization values separated by commas}; 13 */14 a [0] = 0; 15 a [1] = 1; 16 System. out. println (a [0]); 17 System. out. println (a [1]); 18 19 System. out. println ("-----------------------------------"); 20/* incorrect method 21 int [] B = null; 22 for (int I = 0; I <10; I ++) {23 B [I] = I; 24 System. out. println (B [I]); 25} 26 */27 28 29}
Reference array:
1 public class Array {2 3 public static void main (String [] args) {4 Person [] p = new Person [3]; 5 // The Array Memory is for the application data type, pointing to the object, but the initial value is null 6 for (int I = 0; I <p. length; I ++) {7 System. out. println (p [I]); 8} 9 System. out. println ("-------------------------------------"); 10 for (int I = 0; I <p. length; I ++) {11 p [I] = new Person (I * 10); 12 System. out. println (p [I]. age); 13} 14}; 15} 16 class Person {17 int age; 18 public Person (int age) {19 this. age = age; 20} 21}
3. Each array in Java has an attribute named length, which indicates the length of the array. The length attribute is public, final, and int. Once the length of the array is determined, the size cannot be changed.
4. Two-dimensional array. A two-dimensional array is a two-dimensional structure of a plane. It is essentially an array. Two-dimensional array definition: type [] [] a = new type [2] [3];