public static @Nullable <T> T[] trimToSize(@Nullable T[] array, int size) {
    if (array == null || size == 0) {
      return null;
    } else if (array.length == size) {
      return array;
    } else {
      return Arrays.copyOf(array, size);
    }
  }
Removes value from given array if present, providing set-like behavior.
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/ArrayUtils.java