Basic HTML version of Foils prepared Sept 6 1998

Foil 9 Java Language -- More on Arrays

From Java Tutorial 98-2: Java Language and Object Oriented Techniques CPS606 Fall Semester 1999 -- Sept 7 1999. by Geoffrey C. Fox, Nancy McCracken

An example application using an array.
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 Mon Sep 6 1999