Basic HTML version of Foils prepared 18 May 97

Foil 18 Java Language -- More on Arrays

From Java Tutorial - Spring 1997 Part II: Java Language and Object-Oriented Concepts Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


An array of length 128 is subscripted by integers from 0 to 127.
Subscripts are range checked in runtime and so vec[-1] and vec[128] will generate exceptions.
Array length can be extracted via the length instance variable, e.g.
  • int len = vec.length will assign len = 128.
Arrays can have dynamic sizing (a fixed size determined at runtime)
  • int sizeofarray = 67;
  • int vec[] = new int[sizeofarray];
Multidimensional arrays are arrays of arrays
  • char icon[][] = new char[16][16]
  • These arrays can be "ragged":
    • int graph[][] = new int[2][];
    • graph[0][] = new int[4];
    • graph[1][] = new int[7];



© 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 Thu Jan 8 1998