get Not Empty String Else Return Null - Android java.lang

Android examples for java.lang:String Null or Empty

Description

get Not Empty String Else Return Null

Demo Code

import android.content.Context;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String getNotEmptyStringElseReturnNull(String str) {
        try {/*from w w w .j  av  a2s. c  om*/
            if (str != null) {
                str = str.trim();

                if (str.length() > 0) {
                    return str;
                }
            }
        } catch (Throwable e) {
        }
        return null;
    }

}

Related Tutorials