Java examples for java.lang:String Index
Check string index of and handle null value
//package com.java2s; public class Main { public static void main(String[] argv) { String str = "java2s.com"; String searchStr = "2"; System.out.println(indexOf(str, searchStr)); }/*from w ww. j a v a 2 s . c o m*/ public static int indexOf(String str, String searchStr) { if (str == null || searchStr == null) { return -1; } return str.indexOf(searchStr); } }