Array (array), Array array

Source: Internet
Author: User
Tags array definition

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];

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.