Return to Snippet

Revision: 34077
at October 16, 2010 20:39 by studioevoque


Initial Code
public void deleteElementsAt(int[] rows) {
        if(null == rows || rows.length == 0) { 
            return;
        }
        
        int newSize = data.length - rows.length;
        Object[][] newData = new Object[newSize][4];
        int chkIndex = 0;
        int copyIndex = 0;
        for(int i = 0; i < data.length; i++) {
            if( chkIndex < rows.length && i == rows[chkIndex] ) {
                chkIndex++;
            } else {
                newData[copyIndex++] = data[i];
            }
            
        }

        data=newData;
    }

Initial URL


Initial Description
A rough "it works" way to delete elements from an array given the array of indices to delete. A new array is created by copying over the remaining elements.

Any suggestions on how to make this more efficient appreciated :)

Initial Title
Delete elements from an array given an array of indices

Initial Tags
array

Initial Language
Java