Java Reference
In-Depth Information
Let's count those leading digits...
input file name? sunspot.txt
excluding 4144 zeros
Digit Count Percent
1 5405 31.24
2 1809 10.46
3 2127 12.29
4 1690 9.77
5 1702 9.84
6 1357 7.84
7 1364 7.88
8 966 5.58
9 882 5.10
Total 17302 100.00
Notice that on this execution the program reports the exclusion of some 0 values.
Chapter Summary
An array is an object that groups multiple primitive values
or objects of the same type under one name. Each individual
value, called an element, is accessed with an integer index
that ranges from 0 to one less than the array's length.
Several common array algorithms, such as printing an
array or comparing two arrays to each other for equality,
are implemented by traversing the elements and examin-
ing or modifying each one.
Attempting to access an array element with an index of
less than 0 or one that is greater than or equal to the
array's length will cause the program to crash with an
ArrayIndexOutOfBoundsException .
Java arrays are objects and use reference semantics, in
which variables store references to values rather than to
the actual values themselves. This means that two vari-
ables can refer to the same array or object. If the array is
modified through one of its references, the modification
will also be seen in the other.
Arrays are often traversed using for loops. The length of
an array is found by accessing its length field, so the loop
over an array can process indexes from 0 to length - 1 .
Array elements can also be accessed in order using a type
of loop called a for-each loop.
Arrays of objects are actually arrays of references to
objects. A newly declared and initialized array of objects
actually stores null in all of its element indexes, so each
element must be initialized individually or in a loop to
store an actual object.
Arrays have several limitations, such as fixed size and lack
of support for common operations like == and println .
To perform these operations, you must either use the
Arrays class or write for loops that process each ele-
ment of the array.
A multidimensional array is an array of arrays. These are
often used to store two-dimensional data, such as data in
rows and columns or xy data in a two-dimensional space.
 
 
Search WWH ::




Custom Search