/ Published in: Java
                    
                                        
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 :)
                Any suggestions on how to make this more efficient appreciated :)
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
public void deleteElementsAt(int[] rows) {
if(null == rows || rows.length == 0) {
return;
}
int newSize = data.length - rows.length;
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;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                