In this question, the suggested solution for smoosh() is as shown below,public static void smoosh(int[] a) {    int originalPos = 0;    int targetPos = 0;    while (originalPos < a.length) {        // Copy (and remember) one element to the correct position:        int currentElement = a[targetPos++] = a[originalPos++];        // Advance originalPos until a different element is found:        while (originalPos < a.length && a[originalPos] == currentElement) {            originalPos++;        }    }    // Fill remaining elements:    while (targetPos < a.length) {        a[targetPos++] = -1;    }}but, I felt that this well tested new solution shown below looks more readable than shown above,  public static void smoosh(int[] a) {    int saveOriginalPosition = 1;    int targetPosition = 0, originalPosition = 0;    while(targetPosition < a.length){        if(saveOriginalPosition < a.length){            for(originalPosition = saveOriginalPosition;originalPosition < a.length;originalPosition++)                if(a[originalPosition] != a[targetPosition])                {                    a[++targetPosition] = a[originalPosition];                    break;                }            saveOriginalPosition = originalPosition;        }else{            break;        }    }    if(originalPosition == a.length){        for(int setRemaining = targetPosition+1; setRemaining  < a.length; setRemaining++)            a[setRemaining] = -1;    } }because point mentioned by 200_success, i.e., However, being able to recognize the structure of the loop just by looking at the loop header gives it an advantage in readability. is considered in this new solution, whereas the inner while loop of the suggested solution does not look readable.Please let me know your inputs on the changes.
Comparing two implementations of smoosh()
java;array