您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes
Introduction
Content
Apply
Reflect
Extend
previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Content Index
Content Page # 10

Array size

Java arrays provide a value to tell the program the size (number of elements) an array has been defined with. If arr is an array (of any type) then arr.length is the length of the array.

For example, this section of Java: 

int arr = new int[100];
System.out.println( arr.length )
Will print the number "100" as there are 100 elements in array arr Note that "length" is not a method. 
This means that it would be incorrect in this case to write x.length()
This is a cause of some confusion because in the case of the String class (described below) this would be the correct notation! As ever, it takes a bit of practice to get it right. 
Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg