Coll1.java
Select all
/* Coll1.java David Klick CIS 260 2/8/06 This program demonstrates a few features of the Vector class. */ import java.util.*; public class Coll1 { public static void main(String[] args) { Vector
v = new Vector
(); v.add("This"); v.add("is"); v.add("a"); v.add("demonstration"); v.add("of"); v.add("the"); v.add("Vector"); v.add("class"); for (String s : v) System.out.print(s + " "); System.out.println("\nThe vector has " + v.size() + " elements"); System.out.println("The word \"there\" is" + (v.contains("there")?"":" not") + " in the vector"); System.out.println("The word \"class\" is" + (v.contains("class")?"":" not") + " in the vector"); System.out.println("The third element is: " + v.elementAt(2)); System.out.println("The fourth element is: " + v.elementAt(3)); v.set(1, "was"); System.out.println(v); v.remove("This"); v.remove("was"); System.out.println(v); } }