Java Reference
In-Depth Information
Next, consider the following statements:
stringList.addElement("Spring");
stringList.addElement("Summer");
stringList.addElement("Fall");
stringList.addElement("Winter");
After these statements execute, stringList is as shown in Figure 9-22.
stringList
Spring
Summer
Fall
Winter
FIGURE 9-22 stringList after adding four strings
The statement:
System.out.println(stringList);
outputs the elements of stringList in the following form:
[Spring, Summer, Fall, Winter]
The class Vector is contained in the package java.util . Therefore, to use the class
Vector , your program must include either the statement:
import java.util.*;
or the statement:
import java.util.Vector;
The program in Example 9-14 further illustrates how a Vector object works.
EXAMPLE 9-14
//StringVectorExample
import java.util.Vector;
//Line 1
public class StringVectorExample
//Line 2
{
//Line 3
public static void main(String[] arg)
//Line 4
 
Search WWH ::




Custom Search