@SuppressWarnings("unchecked")
  public static @Nullable <T> T[] removeElement(Class<T> kind, @Nullable T[] array, T element) {
    if (array != null) {
      if (!contains(array, element)) return array;
      final int length = array.length;
      for (int i = 0; i < length; i++) {
        if (Objects.equals(array[i], element)) {
          if (length == 1) {
            return null;
          }
          T[] result = (T[]) Array.newInstance(kind, length - 1);
          System.arraycopy(array, 0, result, 0, i);
          System.arraycopy(array, i + 1, result, i, length - i - 1);
          return result;
        }
      }
    }
    return array;
  }
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