Java Utililty Methods String Last Index Of

List of utility methods to do String Last Index Of

Description

The list of methods to do String Last Index Of are organized into topic(s).

Method

intlastIndexOf(String str, String searchChar)
last Index Of
if (isEmpty(str)) {
    return -1;
return str.lastIndexOf(searchChar);
intlastIndexOf(String str, String substr)
last Index Of
if (str != null) {
    return str.lastIndexOf(substr);
} else {
    return -1;
intlastIndexOf(String string, char value, int startIndex, int count)
last Index Of
int leftMost = startIndex + 1 - count;
int rightMost = startIndex + 1;
String substring = string.substring(leftMost, rightMost);
int lastIndexInSubstring = substring.lastIndexOf(value);
if (lastIndexInSubstring < 0)
    return -1;
else
    return lastIndexInSubstring + leftMost;
...
intlastIndexOf(String string, char... chars)
last Index Of
if (string == null) {
    return -1;
return lastIndexOf(string, string.length() - 1, chars);
intlastIndexOf(String string, String substring)
Reimplementation of lastIndexOf from String class to make it work indepent of the platform used.
int len = string.length();
while (len >= -1) {
    if (string.startsWith(substring, len)) {
        return len;
    len--;
return len;
...
intlastIndexOf(String text, int startPos, String... searchStrings)
last Index Of
int bestPos = -1;
for (String i : searchStrings) {
    int pos = text.lastIndexOf(i, startPos);
    if (pos >= 0) {
        if ((bestPos < 0) || (pos > bestPos)) {
            bestPos = pos;
return bestPos;
intlastIndexOf(String text, String key, int num)
last Index Of
int index = -1;
int fromIndex = text.length() - 1;
for (int i = 0; i < num; i++) {
    index = text.lastIndexOf(key, fromIndex);
    fromIndex = index - 1;
return index;
intlastIndexOf(String what, String within)
last Index Of
if (what == null || within == null || what.length() == 0) {
    return -1;
int i = 0;
int lastI = -1;
while ((i = within.indexOf(what, i)) != -1) {
    lastI = i++;
return lastI;
intlastIndexOf(StringBuffer buf, String str)
Performs the equivalent of buf.toString().lastIndexOf(str), but is much more memory efficient.
return lastIndexOf(buf, str, buf.length());
intlastIndexOfAny(final String delimiters, final String str)
last Index Of Any
for (int i = str.length() - 1; i >= 0; --i) {
    if (delimiters.indexOf(str.charAt(i)) >= 0) {
        return i;
return -1;