Android String Empty Check isNullOrEmptyOrOnlyWhitespaces(String string)

Here you can find the source of isNullOrEmptyOrOnlyWhitespaces(String string)

Description

Checks is string null or its length == 0 or it contains only whitespaces, very useful

License

Open Source License

Parameter

Parameter Description
string object to check, can be null :D

Return

true if string is null or its length == 0 or it contains only whitespaces, false otherwise

Declaration

public static boolean isNullOrEmptyOrOnlyWhitespaces(String string) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w  ww. ja va2s  .  c o  m
     * Checks is string null or its length == 0 or it contains only whitespaces, very useful
     *
     * @param string
     *          object to check, can be null :D
     * @return true if string is null or its length == 0 or it contains only whitespaces,
     *          false otherwise
     */
    public static boolean isNullOrEmptyOrOnlyWhitespaces(String string) {
        return isNullOrEmpty(string) ? true : string.trim().length() == 0;
    }

    /**
     * Checks is string null or its length == 0, very useful
     *
     * @param string
     *          object to check, can be null :D
     * @return {@code true} if string is null or its length == 0, {@code false} otherwise
     */
    public static boolean isNullOrEmpty(String string) {
        return string == null || string.length() == 0;
    }
}

Related

  1. isEmpty(String string)
  2. isEmptyString(String s)
  3. isEmptyOrNull(String str)
  4. toNullIfEmptyOrWhitespace(String string)
  5. toNullIfEmpty(String string)
  6. nullToEmpty(String url)
  7. isEmpty(String s)
  8. isEmpty(String s)
  9. isEmpty(String str)