Here you can find the source of lastIndexOf(final String src, final String sub, int startIndex, int endIndex)
public static int lastIndexOf(final String src, final String sub, int startIndex, int endIndex)
//package com.java2s; //License from project: Open Source License public class Main { public static int lastIndexOf(final String src, final String sub, int startIndex, int endIndex) { final int sublen = sub.length(); final int srclen = src.length(); if (sublen == 0) { return (startIndex > srclen) ? srclen : ((startIndex < -1) ? -1 : startIndex); }//from ww w . j a v a2 s . com final int total = srclen - sublen; if (total < 0) { return -1; } if (startIndex >= total) { startIndex = total; } if (endIndex < 0) { endIndex = 0; } final char c = sub.charAt(0); Label_0144: for (int i = startIndex; i >= endIndex; --i) { if (src.charAt(i) == c) { for (int j = 1, k = i + 1; j < sublen; ++j, ++k) { if (sub.charAt(j) != src.charAt(k)) { continue Label_0144; } } return i; } } return -1; } public static int lastIndexOf(final String src, final char c, int startIndex, int endIndex) { final int total = src.length() - 1; if (total < 0) { return -1; } if (startIndex >= total) { startIndex = total; } if (endIndex < 0) { endIndex = 0; } for (int i = startIndex; i >= endIndex; --i) { if (src.charAt(i) == c) { return i; } } return -1; } public static int[] lastIndexOf(final String s, final String[] arr) { return lastIndexOf(s, arr, s.length()); } public static int[] lastIndexOf(final String s, final String[] arr, final int fromIndex) { final int arrLen = arr.length; int index = -1; int last = -1; for (int j = 0; j < arrLen; ++j) { final int i = s.lastIndexOf(arr[j], fromIndex); if (i != -1 && i > index) { index = i; last = j; } } int[] array; if (last == -1) { array = null; } else { final int[] array2 = array = new int[2]; array2[0] = last; array2[1] = index; } return array; } }