文档介绍:×÷Õߣºjeru
email: jeru@
ÈÕÆÚ£º7/3/2001 9:59:06 AM
Declarations and Access Control
Objective 1
Write code that declares, constructs and initializes arrays of any base type using any of the permitted forms, both for declaration and for initialization.
Arrays are Java objects. (An object is a class instance or an array.) and may be assigned to variables of type Object. All methods of class Object may be invoked on an array. If you create an array of 5 Strings, there will be 6 objects created.
Arrays should be
Declared. (int[] a; String b[]; Object []c; Size should not be specified now)
Allocated (constructed). ( a = new int[10]; c = new String[arraysize] )
Initialized. for (int i = 0; i < ; a[i++] = 0)
The above three can be done in one step. int a[] = { 1, 2, 3 }; or int a[] = new int[] { 1, 2, 3 }; But never specify the size with the new statement.
Java arrays are static arrays. Size has to be specified pile time. returns array¡¯s size, cannot be changed. (Use Vectors for dynamic purposes).
Array size is never specified with the reference variable, it is always maintained with the array object. It is maintained in , which is a final instance variable. Note that arrays have a length field (or property) not a length() method. When you start to use Strings you will use the string, length method, as in ();
Anonymous arrays can b