java--Array

Source: Internet
Author: User

"Array"  Note: Arrays can be stored in the stack, but not in Java (because they are references in Java).  "One-dimensional array" statement: type var[]; or type[] var;The Java language cannot specify its length (the number of elements in the array) when generating an array, such as int a[4] is illegal(--because the data in Java is distributed in the heap, it is dynamically allocated; C can).  creation of array objects:array name = new array element type [number of array elements] "Memory allocation"  Note: This means that 5 objects are new in memory, with an initialization value of 0 (the default) for each object. New Int[5] differs from int[] Arr: The former is legal and the latter is illegal.   "element is an array of reference data types" Note: Each element in an array that is a reference data type needs to be instantiated.  Note: The <1>days data type is an array, date[] as a class. <2>days = new Date[3]; Represents a reference type of data, that is, days (in the stack) to a region in the heap date[3]. <3>days[i] = new Date (2004,4,i++); Represents a reference, days[1] points to another area in the heap date (2004,4,1).    "Array Initialization" Dynamic initialization: The array definition is separated from the operation of the array element allocation space and assignment. (be sure to remember that the array must be allocated a good space before use, not necessarily the assignment) Note: <1>int a[];----array definition (STACK)<2>a=new int[3];----Allocated space (heap)<3>a[0]=3;----Assignment operation (heap)      Static initialization: Allocates space and assigns values to the array elements while defining the arrays.    "Default initialization of array elements" An array is a reference type whose elements are equivalent to the member variables of a class, so after the array allocates space, each element is implicitly initialized according to the rules of the member variable.  Note: <1>a[3] is an int type and the int type has a default initial value of 0.<2>days[2] is a reference type, and the default initial value of the reference type is null.  "references to array elements" Note: the length of an array is an attribute, not a method (so do not write A.length ()).  "string[] args"in the main function of Java, enter the following statement:for (int i=0;i<args.length;i++) {System.out.println (Args[i]);  }The compilation runs without any display. input command line arguments: Java test.java aa bb ccoutput: AA bb cc "wrapper class for the underlying type" The general underlying type data is loaded in the stack and needs to be wrapped as an object if it needs to be stored in the heap. For example: Byte-->byte,int-->integer,char-->character ...This enables conversion between data, because the underlying type of data has been converted to a class object, and there is a series of corresponding methods in the API. For example: static double = double (string s),----The passed argument is a String type, and the double type is returned.

java--Array

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.