title: How to copy an object in Java
body: <p>I'm making my own sort of anythink, which implements Comparable interface. Algorithm looks fine, but <code>Comparable a = list.get(i);</code> is a link as i guess, but i need a copy of this object. I cant use <code>list.get(i).copy()</code>, because it is undefined for Comparable.</p>
  
  <pre><code>private static void sortIncrease(ArrayList&lt;Comparable&gt; list) {
      int i, j;
  
      for (i = 1; i &lt; list.size(); i++) {
          Comparable a = list.get(i);
  
          for (j = i - 1 ; j &gt;= 0 ; j = j - 1) {
              int cmpResult = a.compareTo(list.get(j));
  
              if (cmpResult &lt; 0) {
                  list.set(j + 1, list.get(j));
              } else {
                  list.set(j+1, a);
                  break;
              }
          }
      }       
  }
  </code></pre>