HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 73 Review of the Array Class

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * See also color IMAGE

Arrays replace pointer arithmetic. They're created with the new operator:
  • char s[] = new char[30];
Indexing is 0-based.
No multi-dimensional arrays. Must use arrays of arrays:
  • int i[][] = new int[3][4];
Brackets may follow array element type. The following are equivalent:
  • int iarray[];
  • int[] iarray;
  • byte f(int n)[];
  • byte[] f(int n);
Array bounds checking occurs at runtime.
The length of an array can be found by using .length:
  • int a[][] = new int[10][3];
  • System.out.println(a.length); // prints 10
  • System.out.println(a[0].length); // prints 3



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Feb 18 1997