Below function takes an array, an element to be deleted and returns a new array minus the indicated element. Can this be optimized some how? How good is it generally?
public static int[] sbSample(int a[],int i){
int size=0;
int b[]=new int[a.length]; // provide length of new array
for(int k=0;k<a.length;k++){ // iterate over elements of passed array
if(!(a[k]==i)){ // search for elements other than to be deleted in passed array
b[size]=a[k]; // store those arrays in new declared array
size++; // increment counter
}
}
for(int k=0;k<size;k++){
System.out.println(b[k]);
}
return b;
}