Converting to a column oriented array in Java
        Posted  
        
            by halfwarp
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by halfwarp
        
        
        
        Published on 2010-04-29T10:57:37Z
        Indexed on 
            2010/04/29
            11:07 UTC
        
        
        Read the original article
        Hit count: 317
        
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.
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.
Example:
List<List<Object>> column-oriented = new ArrayList<ArrayList<Object>>();
public void newObject(Object[] obj) {
    for(int i = 0; i < obj.length; i++) {
        column-oriented.get(i).add(obj[i]);
    }
}
Note: For simplicity I've omitted the initialization of objects and stuff.
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.
How would you do this knowing it's very performance sensitive?
© Stack Overflow or respective owner