title: Converting to a column oriented array in Java
body: <p>Although I have Java in the title, this could be for any OO language.
  I'd like to know a few new ideas to improve the performance of something I'm trying to do.</p>
  
  <p>I have a method that is constantly receiving an Object[] array. I need to split the Objects in this array through multiple arrays (List or something), so that I have an independent list for each column of all arrays the method receives.</p>
  
  <p>Example:</p>
  
  <pre><code>List&lt;List&lt;Object&gt;&gt; column-oriented = new ArrayList&lt;ArrayList&lt;Object&gt;&gt;();
  
  public void newObject(Object[] obj) {
      for(int i = 0; i &lt; obj.length; i++) {
          column-oriented.get(i).add(obj[i]);
      }
  }
  </code></pre>
  
  <p>Note: For simplicity I've omitted the initialization of objects and stuff.</p>
  
  <p>The code I've shown above is slow of course. I've already tried a few other things, but would like to hear some new ideas.</p>
  
  <p>How would you do this knowing it's very performance sensitive?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've tested a few things and found that:</p>
  
  <p>Instead of using ArrayList (or any other Collection), I wrapped an Object[] array in another object to store individual columns. If this array reaches its capacity, I create another array with twice de size and copy the contents from one to another using System.copyArray. Surprisingly (at least for me) this is faster that using ArrayList to store the inner columns...</p>