package collections;
import java.util.Vector;
import java.util.Iterator;

class vectest {
	public static void main (String[] arg){
		Vector v = new Vector();
		v.addElement("Ena");
		v.addElement("Dyo");
		System.out.println(v);
		
		
		//v.setElementAt("X", 4); // I get outOfBoundsException
		
		
		// Example of overwritting 
		v.setElementAt("X", 1); // Overwrites the reference to "Dyo"
		System.out.println(v);
		
		// Example of insertion
		v.insertElementAt("Dyo", 2);
		System.out.println(v);
		
		
		// Example of size change:  we reduce size and we loose references
		v.setSize(2);  // 
		System.out.println(v);
		
		
		
		//	 Example of size change:  we increase size and have null refererences
		v.setSize(12);  // 
		System.out.println(v);
		//v.addElement("Tria");
		//v.addElement("Tes");
		System.out.println("size="+v.size() + " capacity="+v.capacity());
		
		/*
		// Example of the automatic doubling the capacity of a vector
		v.setSize(22);  // 
		System.out.println(v);
		System.out.println("size="+v.size() + " capacity="+v.capacity());
		
		*/
		
		
		// Example of the capacity shrink
		v.trimToSize();
		System.out.println(v);
		System.out.println("size="+v.size() + " capacity="+v.capacity());

		
		
		// Svhnei ena mono null
		v.addElement("Ena");
		v.removeElement("Ena");
		System.out.println(v);
		System.out.println("size="+v.size() + " capacity="+v.capacity());
	
		
		// Svhnei ola ta nulls		
		System.out.println("Deleting Nulls");
		int i=0;
		while (i < v.size()) {
			if (v.elementAt(i)==null)
				v.removeElementAt(i);
			else i++;  // is this correct?
		}
		System.out.println(v);
		System.out.println("size="+v.size() + " capacity="+v.capacity());
	    /*
		
		// Svhnei ola ta nulls			
		while (v.contains(null)) {
			v.removeElement(null);
		}
		System.out.println(v);
		System.out.println("size="+v.size() + " capacity="+v.capacity());
		
		 */
	}
	
}