title: checking if an object is in a list before adding java
body: <p>Ok so I am having problems with my add method on how to implement checking if an object is already in the arraylist before adding a new one. </p>
  
  <p>I would also like to create a remove method but everytime I attempt to use it I end up with a null pointer exception. </p>
  
  <pre><code>import java.util.*;
  
  public class ContactsArrayList extends AbstractList{
  
      private Contact[] contacts;
      private int size;
  
      public ContactsArrayList(){
      //initializes contactArray with a capacity of 1
          contacts = new Contact[1];
          size = 0;
      }
      public ContactsArrayList(int capacity){
          if(capacity &lt; 0){
              try {
                  throw new Exception("Capacity: must be greater than zero.");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          contacts = new Contact[capacity];
          size = 0;
      }
      public int size(){
          //returns size of list
          return size;
      }
      public boolean isEmpty(){
          return size == 0;
      }
      private void listRangeCheck(int index){
          //checks if index is within range as built in debugging method
          if(index &gt;= size || index &lt; 0){
              throw new IndexOutOfBoundsException("Index: " + index + " is not within the list.");
          }
      }
      public Contact get(int index){
          //returns index at Contact at specified index
          listRangeCheck(index);
          return contacts[index];
      }
      public void capacityCheck(int minCapacity){
          //checks current capacity if capacity is less than required,
          // array copies its current values over to an array double the size
          int oldCapacity = contacts.length;
          if(minCapacity &gt; oldCapacity){
              int newCapacity = (oldCapacity * 2);
              if(newCapacity &lt; minCapacity)
                  newCapacity = minCapacity;
              contacts = Arrays.copyOf(contacts, newCapacity);
          }
      }
      public boolean add(Contact contact){
      //appends the specified element to the end
          capacityCheck(size + 1);
          contacts[size++] = contact;
          return true;
      }
      public int capacity(){
      //returns ContactArray size
          return contacts.length;
      }
      public void sort() {
          //sorts the specified contact array list
          List&lt;Contact&gt; c_list = new ArrayList();
          c_list = Arrays.asList(contacts);
          Collections.reverse(c_list);
          c_list.toArray(contacts);
      }
  }
  </code></pre>