O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required