title: How could I write multiple "compareTo" methods in just one class?
body: <p>I'm comparing and sorting multiple attribute by two objects, but for that I created different classes to compare those different attributes.</p>
  
  <p>This is in my main class:</p>
  
  <pre><code>Collections.sort(Comparator, new SortByRef());
          System.out.println("\nOrdenado por Referencia");
          for(int i=0; i&lt;Comparator.size(); i++)
              System.out.println(Comparator.get(i));
  
  
          Collections.sort(Comparator, new SortByMonto());
          System.out.println("\nOrdenado por Monto");
          for(int i=0; i&lt;Comparator.size(); i++)
              System.out.println(Comparator.get(i));
  
          Collections.sort(Comparator, new SortByDes());
          System.out.println("\nOrdenado por Descripcion");
          for(int i=0; i&lt;Comparator.size(); i++)
              System.out.println(Comparator.get(i));
  
          Collections.sort(Comparator, new SortByNP());
          System.out.println("\nOrdenado por Numero de parte");
          for(int i=0; i&lt;Comparator.size(); i++)
              System.out.println(Comparator.get(i));
  </code></pre>
  
  <p>As you can see, in <code>Collections.sort</code>, I created different <code>SortBy...</code>, I mean, different classes for each one.</p>
  
  <p>But I want to create just ONE class to compare all the attributes. How could I do it?</p>
  
  <p>For example, these are my methods I created:</p>
  
  <pre><code>public int compare(COSTOS ref1, COSTOS ref2) {
          return ref1.referencia - ref2.referencia;}
  
  public int compare(COSTOS monto1, COSTOS monto2) {
          return (int) (monto1.monto - monto2.monto);
      }
  </code></pre>