Basic HTML version of Foils prepared 18 May 97

Foil 21 The Vector class

From Java Tutorial - Spring 1997 Part 4: Multithreading, useful Java classes, I/O, Networking, and the future Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


1 In Java, while you can give the size of arrays at run time, you cannot dynamically change the size of an array during the computation. The vector class provides a data structure with this property - the restriction is that all of the elements must be of type Object.
  • It is usually simple to 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". It always starts with 0 elements. As you add elements, if the initial capacity is exceeded, then more memory is automatically allocated in the size of the capacity increment. The default is an initial capacity of 10 and an increment which doubles each time.
  • Vector shoes = new Vector();
  • 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 Thu Jan 8 1998