Function to remove element from an array 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&lt;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&lt;size;k++){
        System.out.println(b[k]);
    }
    return b;
}
The methodname sbSample doesn't tell anything about what the method is doing and this will make debugging the code very hard if not impossible.  

You should leave your methodparameters some space to breathe so int a[],int i should be int a[], int i. The same is true for variables and operators.  

Comments should tell the reader of the code why something is done in the way it is done. Stating the obvious what is done is only adding noise to the code and should be removed. Let the code itself tell what is done by using meaningful names for classes, methods and variables.  

This method is doing to much hence it is breaking the single responsibility principle. It is "deleting" array elements and displaying the resulting array values.   

If the source array has 10 elements and 3 of them have the value which you want to delete, the resulting array still has 10 elements which is somehow strange. Deleting means IMO that the size of the array should shrink afterwards. How about using an ArrayList&lt;T&gt; adding the items which aren't satisfying the search condition and later call toArray() to return the resulting array ?