Basic HTML version of Foils prepared 17 Nov 97

Foil 24 The Vector Class

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo


1 In Java, while you can give the size of an array at run time, you cannot dynamically change the size of an array during the computation. The vector class provides a data structure with just this property, but the restriction is that all of the elements must be of type Object.
  • Usually, we insert an element of any type and Java will convert it to an Object, but when you extract an element, you must explicitly cast it to convert it back to the type you want.
2 A vector is created with an "initial capacity" and a "capacity increment". (The default is an initial capacity of 10 and an increment that doubles each time.) As you add elements, if the initial capacity is exceeded, then more memory is automatically allocated in the size of the capacity increment.
3 Vector shoes = new Vector();
4 Vector orders = new Vector(100, 10);

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