title: How to do union, intersect, difference and reverse data in java
body: <p>I want to implement the union, intersect, difference and reverse operations in Java.</p>
  
  <p>First I have 2 instances of <code>ArrayList&lt;Integer&gt;</code></p>
  
  <pre><code>a = [0,2,4,5,6,8,10]
  b = [5,6,7,8,9,10]
  </code></pre>
  
  <p>a union b should return <code>c = [0,2,4,5,6,7,8,9,10]</code></p>
  
  <p>a intersect b should return <code>c = [5,8,10]</code></p>
  
  <p>a difference b should return <code>c = [0,2,4]</code></p>
  
  <p>reverse <code>a = [10,8,6,5,4,2,0]</code></p>
  
  <p>Something like this.</p>
  
  <p>How to implement that method in Java?</p>
  
  <hr>
  
  <p><strong>Update</strong>: I have to start with this template:</p>
  
  <pre><code>package IntSet;
  import java.util.ArrayList;
  import java.util.Collection;
  
  
  public class IntSet {
  
  private ArrayList&lt;Integer&gt; intset;
  
  public IntSet(){
      intset = new ArrayList&lt;Integer&gt;();
  }
  
  public void insert(int x){
      intset.add(x);
  }
  
  public void remove(int x){
      //implement here
      intset.indexOf(x);
  }
  
  public boolean member(int x){
      //implement here
      return true;
  }
  
  public IntSet intersect(IntSet a){
      //implement here
      return a;
  }
  
  public IntSet union(IntSet a){
      //implement here
      return a;
  }
  
  public IntSet difference(IntSet a){
      //implement here
      IntSet b = new IntSet();
      return b; 
  }
  </code></pre>