Java examples for java.lang:String Index
Find the last Index Of a char inside a string
public class Main { public static void main(String[] argv) { String str = "java2s.com"; char searchChar = 'o'; System.out.println(lastIndexOf(str, searchChar)); }/*w ww. j av a 2 s . c om*/ public static int lastIndexOf(String str, char searchChar) { if (isEmpty(str)) { return -1; } return str.lastIndexOf(searchChar); } public static int lastIndexOf(String str, String searchStr) { if (str == null || searchStr == null) { return -1; } return str.lastIndexOf(searchStr); } public static boolean isEmpty(String str) { return str == null || str.length() == 0; } }