Java Reference
In-Depth Information
The output from the program is shown here:
4. Although the Bubble sort is good for small arrays, it is not efficient when used on lar-
ger ones. The best general-purpose sorting algorithm is the Quicksort. The Quicksort,
however, relies on features of Java that you have not yet learned about.
Multidimensional Arrays
Although the one-dimensional array is the most commonly used array in programming,
multidimensional arrays (arrays of two or more dimensions) are certainly not rare. In Java,
a multidimensional array is an array of arrays.
Two-Dimensional Arrays
The simplest form of the multidimensional array is the two-dimensional array. A two-di-
mensional array is, in essence, a list of one-dimensional arrays. To declare a two-dimen-
sional integer array table of size 10, 20 you would write
Pay careful attention to the declaration. Unlike some other computer languages, which use
commas to separate the array dimensions, Java places each dimension in its own set of
brackets. Similarly, to access point 3, 5 of array table , you would use table[3][5] .
In the next example, a two-dimensional array is loaded with the numbers 1 through 12.
Search WWH ::




Custom Search