Android examples for java.lang:String Search
index Of string and handle null value
import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLEncoder; import java.security.SecureRandom; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Locale; public class Main{ /**//w w w . j a va 2s . c o m * * <pre> * StringUtil.indexOf(null, *) = -1 * StringUtil.indexOf(*, null) = -1 * StringUtil.indexOf("", "") = 0 * StringUtil.indexOf("aabaabaa", "a") = 0 * StringUtil.indexOf("aabaabaa", "b") = 2 * StringUtil.indexOf("aabaabaa", "ab") = 1 * StringUtil.indexOf("aabaabaa", "") = 0 * </pre> */ public static int indexOf(String str, String searchStr) { if (str == null || searchStr == null) { return -1; } return str.indexOf(searchStr); } }