title: Why does List.add(E) return boolean while List.Add(int, E) returns void?
body: <p>Looking at the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#add%28E%29">javadoc</a> I saw the that an ArrayList has an overloaded add method:</p>
  
  <blockquote>
    <p>public boolean add(E e)</p>
    
    <p>Appends the specified element to the end of this list.</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>public void add(int index,
         E element)</p>
    
    <p>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).</p>
  </blockquote>
  
  <p>I noticed that the first one returned a <code>boolean</code> while the second one was a <code>void</code>. As it turns out, the first <code>add</code> HAS to return a <code>boolean</code> because:</p>
  
  <blockquote>
    <p>Returns:
        true (as specified by Collection.add(E))</p>
  </blockquote>
  
  <p>So I went to <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html#add%28E%29">Collection.add(E)</a>:</p>
  
  <blockquote>
    <p>boolean add(E e)</p>
    
    <p>Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)</p>
  </blockquote>
  
  <p>So my question is, why is <code>add</code> specified to return boolean instead of being a void? When I <code>add</code> something I would expect to only do an operation. </p>
  
  <p>I understand that there's other data structures that, as opposed to ArrayList, do not allow duplicates (such as sets). But even then, couldn't the problem be solved along the lines of:</p>
  
  <pre><code>public void add(E e){
      if(e is not in set){
          add e;
      }
  }
  </code></pre>
  
  <p>That way if <code>e</code> IS in the set no action is taken. Why is it better to return a <code>boolean</code> instead of the <code>void</code> approach?</p>