title: Swap Object Array Members Java
body: <p>I'm trying to write an interface method that takes an array of various objects and swaps two of the array elements based on the return of the object's getMeasure() method.</p>
  
  <p>My question is how to swap two array elements when it is an object or how to store a temp object's values when you don't know what the object is necessarily.</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>public static void swapMinAndMax(Measurable[] objects)
  {  
      double largest = 0;
      int lgIndex = 0;
      int smIndex = 0;
  
      for(int i = 1; i &lt; objects.length; i++)
      {
          if(objects[i].getMeasure() &gt; largest){
              largest = objects[i].getMeasure();
              lgIndex = i;
          }                 
      }
      for(int i = 0; i &lt; objects.length; i++)
      {
          if(objects[i].getMeasure() &lt; largest){
              largest = objects[i].getMeasure();
              smIndex = i;
          }        
      }
      //need to swap objects[lgIndex] with objects[smIndex]
  }
  </code></pre>