public void shrinkToFit() {
    int sz = arr.length;
    int newSz = 0;

    for (int i = 0; i < sz; i++) {
      if (arr[i] != null) {
        newSz++;
      }
    }

    if (sz == newSz) {
      return;
    }

    throwIfImmutable();

    Object[] newa = new Object[newSz];
    int at = 0;

    for (int i = 0; i < sz; i++) {
      Object one = arr[i];
      if (one != null) {
        newa[at] = one;
        at++;
      }
    }

    arr = newa;
    if (newSz == 0) {
      setImmutable();
    }
  }
Shrinks this instance to fit, by removing any unset ({@code null}) elements, leaving the
remaining elements in their original order.
android/android_framework/dex-maker/src/main/java/com/android/dx/util/FixedSizeList.java