Java Reference
In-Depth Information
FIGURE 2.4
The
july
reference points to array of 31 GregorianCalendar references.
day
1
month
7
array reference
year
2010
0
1
2
3
.
.
30
july
null
null
null
A GregorianCalendar
object
null
array object of 31
GregorianCalendar
references
Using Arrays
Every array has an attribute named
length
that is the size of the array. The
length
attribute is particularly useful when using a
for
loop to iterate through the elements of the
array. For example, the following
for
loop initializes the 31
GregorianCalendar
references
in the
july
array:
13. GregorianCalendar [] july;
14. july = new GregorianCalendar[31];
15. int year = 2010, month = 7;
16. for(int i = 0; i < july.length; i++) {
17. july[i] = new GregorianCalendar(year, month, i+1);
18. }
Search WWH ::
Custom Search