Compare string and handle null value - Android java.lang

Android examples for java.lang:String Compare

Description

Compare string and handle null value

Demo Code


public class Main{
    public static boolean emptyOrNull(String str) {
        return str == null || str.length() == 0;
    }/*w  w  w. ja va 2 s  .  c  om*/
    /**
     *
     * @param firstStr
     * @param secondStr
     * @return
     */
    public static boolean stringCompare(String firstStr, String secondStr) {
        if (emptyOrNull(firstStr)) {
            return false;
        }
        if (firstStr.compareTo(secondStr) > 0) {
            return true;
        } else {
            return false;
        }
    }

}

Related Tutorials