title: How can compare 2 elements of each pair in the Arraylist(Java)
body: <p>I have an interface Pair</p>
  <pre><code>import java.util.ArrayList;
  
  public interface Pair&lt;T,M&gt; {
      public T getFirst();
      public M getSecond();
      public ArrayList&lt;Pair&lt;T,M&gt;&gt; Compare(ArrayList&lt;Pair&lt;T,M&gt;&gt; list);
  }
  </code></pre>
  <p>and an class called MatchingPairs that implement the Pair interface:</p>
  <pre><code>import java.util.ArrayList;
  
  public class MatchingPairs implements Pair&lt;Integer, Integer&gt; {
  
      @Override
      public Integer getFirst() {
          return null;
      }
  
      @Override
      public Integer getSecond() {
          return null;
      }
  
      @Override
      public ArrayList&lt;Pair&lt;Integer, Integer&gt;&gt; Compare(ArrayList&lt;Pair&lt;Integer, Integer&gt;&gt; list) {
          return null;
      }
  }
  </code></pre>
  <p>I dont know how to compare the first element and the second element of each pair by implementing the compare method.</p>