Android examples for java.lang:String Null or Empty
Check if string has Length
import android.content.Context; import android.text.TextUtils; import android.util.Log; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Locale; public class Main{ /**/*from w w w . j a va2 s . com*/ * Check that the given CharSequence is neither {@code null} nor of length 0. * Note: Will return {@code true} for a CharSequence that purely consists of whitespace. * <p><pre class="code"> * StringUtils.hasLength(null) = false * StringUtils.hasLength("") = false * StringUtils.hasLength(" ") = true * StringUtils.hasLength("Hello") = true * </pre> * @param str the CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not null and has length * @see #hasText(String) */ public static boolean hasLength(CharSequence str) { return (str != null && str.length() > 0); } /** * Check that the given String is neither {@code null} nor of length 0. * Note: Will return {@code true} for a String that purely consists of whitespace. * @param str the String to check (may be {@code null}) * @return {@code true} if the String is not null and has length * @see #hasLength(CharSequence) */ public static boolean hasLength(String str) { return hasLength((CharSequence) str); } }