replace String and handle null value - Android java.lang

Android examples for java.lang:String Replace

Description

replace String and handle null value

Demo Code


public class Main{
    public static boolean emptyOrNull(String str) {
        return str == null || str.length() == 0;
    }//from  www.  ja v a2 s.  c  o m
    public static String replaceStr(String str, String src, String aim) {
        if (emptyOrNull(str) || emptyOrNull(src)) {
            return "";
        }
        if (str.contains(src)) {
            return str.replace(src, aim);
        }
        return str;
    }

}

Related Tutorials