String ends With and handle null value - Android java.lang

Android examples for java.lang:String Starts or Ends

Description

String ends With and handle null value

Demo Code

import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**/*from w ww. j  a v a2s.co m*/
     * 
     * <pre>
     * StringUtil.endsWith(null, *)    = false
     * StringUtil.endsWith(*, null)    = false
     * StringUtil.endsWith("han", "h") = false
     * StringUtil.endsWith("han", "n") = true
     * </pre>
     */
    public static boolean endsWith(String str, String suffix) {
        if (str == null || suffix == null) {
            return false;
        }
        return str.endsWith(suffix);
    }

}

Related Tutorials