Adapted from {@code com.google.common.base.Strings#emptyToNull}.
344200
@SuppressWarnings("unchecked")
  public static <T> T[] toArray(Iterable<? extends T> iterable, Class<T> type) {
    Collection<T> collection;
    if (iterable instanceof Collection) {
      collection = (Collection<T>) iterable;
    } else {
      collection = new ArrayList<T>();
      for (T element : iterable) {
        collection.add(element);
      }
    }
    T[] array = (T[]) Array.newInstance(type, collection.size());
    return collection.toArray(array);
  }
1112053
public static <T> List<T> emptyToNull(final List<T> list) {
        if (isEmpty(list)) {
            return null;
        } else {
            return list;
        }
    }
315672
@CheckForNull
    public static String fixEmpty(@CheckForNull String s) {
        if(s==null || s.length()==0)    return null;
        return s;
    }
49921
public static String emptyToNull(String str) {
        return (str != null && !str.isEmpty()) ? str : null;
    }
91170
public static String checkNull(String val) {
    if (val == null) {
      return null;
    }

    val = val.trim();
    if (val.length() == 0) {
      return null;
    }

    return val;
  }
461245
@SuppressWarnings("unchecked")
    public static <S, I, O> ExtensionResult<S, I, O> empty() {
        return (ExtensionResult<S, I, O>) EMPTY;
    }
88193
@Nullable
    public static String nullableString(@Nullable String str) {
        return str == null || str.isEmpty() ? null : str;
    }
1112526
public static AllowableValues emptyToNull(AllowableValues newValue, AllowableValues current) {
    if (newValue != null) {
      if (newValue instanceof AllowableListValues) {
        return defaultIfAbsent(emptyListValuesToNull((AllowableListValues) newValue), current);
      } else {
        return defaultIfAbsent(newValue, current);
      }
    }
    return current;
  }
107270
public static <T> List<T> nullToEmpty(final List<T> list) {
        return list == null ? N.<T> emptyList() : list;
    }
773235
public static NodeSequence emptySequence( final int width ) {
        assert width >= 0;
        return new NodeSequence() {
            @Override
            public int width() {
                return width;
            }

            @Override
            public Batch nextBatch() {
                return null;
            }

            @Override
            public long getRowCount() {
                return 0;
            }

            @Override
            public boolean isEmpty() {
                return true;
            }

            @Override
            public void close() {
            }

            @Override
            public String toString() {
                return "(empty-sequence width=" + width() + ")";
            }
        };
    }
1175658
@NotNull
    @Contract(pure = true)
    @SuppressWarnings("unchecked")
    public static <T> Optional<T> empty() {
        return (Optional<T>) EMPTY;
    }
1045103
public static boolean isEmpty(final Collection<String> c) {
        if (c == null || c.isEmpty()) {
            return false;
        }
        for (final String text : c) {
            if (isNotEmpty(text)) {
                return false;
            }
        }
        return true;
    }
747964
public static <K, V> SortedMap<K, V> nullToEmpty(final SortedMap<K, V> map) {
        return map == null ? N.<K, V> emptySortedMap() : map;
    }
1277700
public static boolean isEmpty(@Nullable String str) {
        if (str == null || str.length() == 0) {
            return true;
        }
        return false;
    }
1098055
public static String trimAndNullIfEmpty(final String text) {
        if (text != null && !text.trim().isEmpty()) {
            return text.trim();
        }
        return null;
    }
808436
public static <T> SortedSet<T> nullToEmpty(final SortedSet<T> set) {
        return set == null ? N.<T> emptySortedSet() : set;
    }
509305
public static <T> Iterator<T> nullToEmpty(final Iterator<T> iter) {
        return iter == null ? N.<T> emptyIterator() : iter;
    }