Storing Objects of the Same Class in Vectors
An important decision to make when writing a computer program is where to store data. In the first half of this book, you’ve found three useful places to keep information: basic data types such as int
and char
, arrays, and String
objects.
Any Java class can hold data. One of the most useful is Vector
, a data structure that holds objects of the same class.
Vectors are like arrays, which also hold elements of related data, but they can grow or shrink in size at any time.
The Vector
class belongs to the java.util
package of classes, one of the most useful in the Java class library. An import
statement makes it available in your program:
import java.util.Vector;
A vector holds objects that either belong ...
Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.