Java String Last Index Of lastIndexOf(CharSequence charSeq, char ch)

Here you can find the source of lastIndexOf(CharSequence charSeq, char ch)

Description

last Index Of

License

MIT License

Declaration

public static int lastIndexOf(CharSequence charSeq, char ch) 

Method Source Code

//package com.java2s;
/*!//from w w  w  .j  av  a2 s .  co m
 * mifmi-commons4j
 * https://github.com/mifmi/mifmi-commons4j
 *
 * Copyright (c) 2015 mifmi.org and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 */

public class Main {
    public static int lastIndexOf(CharSequence charSeq, char ch) {
        if (charSeq == null) {
            return -1;
        }
        return lastIndexOf(charSeq, ch, charSeq.length() - 1);
    }

    public static int lastIndexOf(CharSequence charSeq, char ch, int fromIndex) {
        if (charSeq == null) {
            return -1;
        }
        for (int i = fromIndex; 0 <= i; i--) {
            char c = charSeq.charAt(i);
            if (c == ch) {
                return i;
            }
        }
        return -1;
    }

    public static int lastIndexOf(CharSequence charSeq, char[] ch) {
        if (charSeq == null) {
            return -1;
        }
        return lastIndexOf(charSeq, ch, charSeq.length() - 1);
    }

    public static int lastIndexOf(CharSequence charSeq, char ch[], int fromIndex) {
        if (charSeq == null) {
            return -1;
        }
        for (int i = fromIndex; 0 <= i; i--) {
            char c = charSeq.charAt(i);
            for (int j = 0; j < ch.length; j++) {
                if (c == ch[j]) {
                    return i;
                }
            }
        }
        return -1;
    }
}

Related

  1. lastIndexOf(char ch, String str)
  2. lastIndexof(char chr, int pos, CharSequence str)
  3. lastIndexOf(CharSequence chars, String searched)
  4. lastIndexOf(CharSequence cs, int searchChar, int start)
  5. lastIndexOf(CharSequence haystack, char needle)
  6. lastIndexOf(CharSequence s, char c, int start, int end)
  7. lastIndexOf(CharSequence s, CharSequence seq)