I have a user give me a random array of objects, I want to do some error checking and basically I want the null objects to be at the end of the array, so that the middle of the array is made up of only non-null objects (sorting of the objects doesn't matter).
Here is what I have, it isn't working. Can anyone please help.
private void properArray(){
    int i = 0;
    int j;
    int cap = theHeap.length;
    for(; i < (cap-1); i++){
        if (theHeap[i] == null){
            j = i + 1;
            while(j < (cap-1)){
                if(theHeap[j] != null){
                    theHeap[i] = theHeap[j];
                    theHeap[j] = null;
                }
                j++;  
            }
        }
    } 
}


