if one string equals another string and handle null - Android java.lang

Android examples for java.lang:String Equals

Description

if one string equals another string and handle null

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//www. j a  va2  s. co  m
     * <pre>
     * StringUtil.equals(null, null) = true
     * StringUtil.equals(null, "abc") = false
     * StringUtil.equals("abc", null) = false
     * StringUtil.equals("abc", "abc") = true
     * StringUtil.equals("abc", "ABC") = false
     * </pre>
     */
    public static boolean equals(String str1, String str2) {
        if (str1 == null) {
            return str2 == null;
        }

        return str1.equals(str2);
    }

}

Related Tutorials