title: Using Vectors in Java ? (Specifically constructors)
body: <p>I'm fairly certain I didn't create the constructors correctly. The fact that I'm working with Vectors (not by choice) is confusing to me. Have I done this right? Is there a deep copy method for Vectors?</p>
  
  <p>Thank you for any help.</p>
  
  <pre><code>import java.util.Vector; 
  import java.util.Iterator;
  
  public class ListVectorBased&lt;E&gt; implements ListInterface&lt;E&gt;, Iterable&lt;E&gt; {
  
      /** array on which the list is based */
      private Vector&lt;E&gt; items;    
  
      /** default Constructor */
      public ListVectorBased() {      
      }
  
      /** constructor with the first item: constructs a list with the
       * specified item as single element of this list
       * @param item first element of the list
       */
      public ListVectorBased(E elt) {
          items.add(1, elt);
      }
  
      /** copy constructor: create a duplicate of the specified list
       * @param list to be copied
       */
      public ListVectorBased(Vector&lt;E&gt; items) {
          this.items = items;
      }
  
  
      /** Tests if this list has no elements.
       * @return &lt;code&gt;true&lt;/codeif this list has no elements;
       * &lt;code&gt;false&lt;/codeotherwise.
       */
      public boolean isEmpty() {
          return items.isEmpty();
      } // end isEmpty
  
  
      /**
       * Returns the number of elements in this list.
       * @return the number of elements in this list.
       */
      public int size() {
          return items.size();
      }  // end size
  
      /**
       * Remove all the elements in this list.
       */
      public void removeAll() {
          items.removeAllElements();
      } // end removeAll
  
  
      /**
       * Inserts the specified element at the specified position in this
       * list. Shifts the element currently at that position (if any)
       * and any subsequent elements to the right (adds one to their
       * indices).
       * @param index index at which the specified element is to be
       * inserted.
       * @param item element to be inserted.
       * @throws IndexOutOfBoundsException - if index is out of range
       * (index &lt; 0 || index size()).
       */
      public void add(int index, E item) throws ListIndexOutOfBoundsException {
          if (index &gt;= 1 &amp;&amp; index &lt;= items.size()+1) {
              items.add(index-1,item);
          } else {  // index out of range
              throw new ListIndexOutOfBoundsException("ListIndexOutOfBoundsException on add");
          }  // end if
      } //end add
  
  
      /**
       * appends the specified element to the end of this list.
       * @param elt element to be added at the end of the list
       */
      public void append(E elt) {
          add (items.size()+1, elt);
      }
  
      /**
       * Returns the element at the specified position in this list.
       * @param index index of element to return.
       * @return the element at the specified position in this list.
       * @throws IndexOutOfBoundsException - if index is out of range
       * (index &lt; 0 || index size()).
       */
      public E get(int index)     throws ListIndexOutOfBoundsException {  
          if (index &gt;= 1 &amp;&amp; index &lt;= items.size()) {
              return items.get(index-1);
          } else {  // index out of range
              throw new ListIndexOutOfBoundsException(
                              "ListIndexOutOfBoundsException on get");    
          }  // end if
      } // end get
  
  
      /**
       * Removes the element at the specified position in this
       * list. Shifts any subsequent elements to the left (subtracts one
       * from their indices).
       * @param index the index of the element to remove
       * @throws IndexOutOfBoundsException - if index is out of range
       * (index &lt; 0 || index size()).
       */
      public void remove(int index) throws ListIndexOutOfBoundsException {
          if (index &gt;= 1 &amp;&amp; index &lt;= items.size()) {
              // delete item by shifting all items at 
              // positions index toward the beginning of the list
              // (no shift if index == size)
              items.remove(index-1);
          } else {  // index out of range
              throw new ListIndexOutOfBoundsException(
                              "ListIndexOutOfBoundsException on remove");
          }  // end if
      } //end remove
  
  
      /**  delete
       * delete the the specified element in this list if exists. Shifts
       * any subsequent elements to the left (subtracts one from their
       * indices).
       * @param elt the element, if it exists, to delete
       */
      public void delete (E elt) {
          if (items.contains(elt)) {
              items.remove(elt);
          }
      }
  
      /** contains
       * Looks for the index of the specified element in this list. If
       * the element is not present, the method returns &lt;code&gt;-1&lt;/code&gt;
       * @param elt the element which index is looked for.
       * @return either the index of the location in the list where the
       * argument is present or &lt;code&gt;-1&lt;/codeif the argument is not
       * contained in the list.
       */
      public int contains(E elt) {
          for (int idx = 1; idx &lt;= items.size(); idx++) {
              if (items.get(idx).equals(elt))
                  return idx;
              else
                  return -1;
          } // end for
      } //end contains
  
  
      /** display
       * Prints all the elements in this list on the console in sequence
       */
      public void display() {
          for (int idx = 1; idx &lt;= items.size(); idx++) {
              System.out.print(items.get(idx));
          } //end for
      } //end display
  
  
  
      /** method to make the class iterable */
  
      public Iterator&lt;E&gt; iterator(){
          return items.iterator();
      }
  
  }  // end ListVectorBased
  </code></pre>