Basic HTML version of Foils prepared July 6 99

Foil 26 Arrays

From Use of Java Language in Computational Science DoD Modernization Users Group Conference Monterey -- June 7 99. by Nancy McCracken, Geoffrey C. Fox


1 Arrays are objects, but have a special syntax for creating and indexing, more like C and C++.
  • int states [ ]; declares the states variable to be a 1D array of ints
  • states = new int [ 128 ]; creates the new 1D array of length 128
  • states [ 27 ] = i + 1; assigning to an element
2 For an array of length n, indices run from 0 to n-1. There is run-time checking of indices.
3 Multi-dimensional arrays are arrays of arrays
  • char states [ ] [ ] = new char [12 ] [ 24 ]; delaring and creating at the same time
  • they can also be "ragged"
  • Note that different rows or columns may not be assumed to be stored contiguously in memory.
4 Arrays can have values that are any type of object
  • Color hues = new Color [ 1024 ];

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 Tue Jul 6 1999