Basic HTML version of Foils prepared Sept 6 1998

Foil 8 Java Language -- Types: Array

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


1 Arrays are "true" or "first class" objects in Java and no pointer arithmetic is supported.
2 Like other objects, an array must be declared and created:
  • int states[]; // declaration
  • alternative syntax: int[] vec;
  • and then:
  • states = new int[128]; // creation
  • or concisely:
  • int states[] = new int[128];
3 Arrays of arbitrary objects can be constructed,
  • e.g. Color manycolors[] = new Color[1024];
  • The only difference is that in the case of primitive types, the array elements are actually created. In the case of arbitrary objects, an array of object references is created; before you use array elements, you must call the constructor of that type for each element.

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 Mon Sep 6 1999