Basic HTML version of Foils prepared 19 July 97

Foil 8 Java Language -- More on Arrays

From Java Tutorial - Summer 1997 Part II: Java Language and Object-Oriented Concepts CEWES Tutorial -- July 22-25 1997. by Nancy J. McCracken,Geoffrey C. Fox

An example application using an array.
1 An array of length 128 is subscripted by integers from 0 to 127.
2 Subscripts are range checked in runtime and so vec[-1] and vec[128] will generate exceptions.
3 Array length can be extracted via the length instance variable, e.g.
  • int len = vec.length will assign len = 128.
4 Arrays can have dynamic sizing (a fixed size determined at runtime)
  • int sizeofarray = 67;
  • int vec[] = new int[sizeofarray];
5 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];

in Table To:


© 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 Wed Apr 1 1998