Java tutorial
//package com.java2s; import android.text.TextUtils; public class Main { public static String DEFAULT_EMPTY = ""; /** * * @param str * @return */ public static String isEmptyOrNull(String str) { if (TextUtils.isEmpty(str)) { return DEFAULT_EMPTY; } return str; } /** * is null or its length is 0 * * <pre> * isEmpty(null) = true; * isEmpty("") = true; * isEmpty(" ") = false; * </pre> * * @param str * @return if string is null or its size is 0, return true, else return false. */ public static boolean isEmpty(CharSequence str) { return (str == null || str.length() == 0); } /** * get length of CharSequence * * <pre> * length(null) = 0; * length(\"\") = 0; * length(\"abc\") = 3; * </pre> * * @param str * @return if str is null or empty, return 0, else return {@link CharSequence#length()}. */ public static int length(CharSequence str) { return str == null ? 0 : str.length(); } }