// Oefening VectorTest, D&D 5, blz 1100,..

import java.util.*;

public class H21_VectorTest {
	
	private static final String kleuren[] = { "rood","wit","blauw" };
	
	public H21_VectorTest() {
		Vector vector = new Vector();
		printVector(vector);
		
		vector.add("paars");
		
		for (int i = 0;i < kleuren.length; i++)
			vector.add(kleuren[i]);
		
		vector.add("orange");
		printVector(vector);
		
		try {
			System.out.println("Het eerste element is: " + vector.firstElement());
			System.out.println("Het laatste element is: " + vector.lastElement());
		}
		catch (NoSuchElementException x) {
			x.printStackTrace();
		}
		
		if (vector.contains("rood"))
			System.out.println("\n\"rood\" is gevonden op index: " + vector.indexOf("rood"));
		else
			System.out.println("\n\"rood\" is niet gevonden");
		
		vector.remove("rood");
		System.out.println("\n\"rood\" is verwijderd uit vector\n");
		printVector(vector);
		
		if (vector.contains("rood"))
			System.out.println("\n\"rood\" is gevonden op index: " + vector.indexOf("rood"));
		else
			System.out.println("\n\"rood\" is niet gevonden");
		
		System.out.println("\nGrootte: " + vector.size() + "\nCapacity: " + vector.capacity());
		
		
	}
	
	private void printVector(Vector v) {
		
		if (v.isEmpty())
			System.out.print("'vector' is leeg");
		else {
			System.out.print("'vector' bevat: ");
			Enumeration items = v.elements();
			
			while (items.hasMoreElements())
				System.out.print(items.nextElement() + " ");
		}
		
		System.out.println("\n");
	}
	
	public static void main (String args[]) {
		new H21_VectorTest();
	}

}
