Java String Last Index Of lastIndexof(char chr, int pos, CharSequence str)

Here you can find the source of lastIndexof(char chr, int pos, CharSequence str)

Description

Charsequence util - lastIndexOf

License

Apache License

Parameter

Parameter Description
chr a parameter
str a parameter

Return

position of last found char

Declaration

public static int lastIndexof(char chr, int pos, CharSequence str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  w w  . j  a v  a 2s. co m*/
     * Charsequence util - lastIndexOf
     *
     * @param chr
     * @param str
     * @return position of last found char
     */
    public static int lastIndexof(char chr, int pos, CharSequence str) {
        int rollPos;
        for (rollPos = pos - 1; rollPos > -1; rollPos--) {
            if (str.charAt(rollPos) == chr)
                break;
        }

        return rollPos;
    }

    /**
     *
     * @param chr
     * @param pos
     * @param source
     * @return
     */
    private static int lastIndexof(char chr, int pos, byte[] source) {
        int rollIndex;

        // Validation
        if (source.length == 0)
            return -1;

        for (rollIndex = pos; rollIndex > -1; rollIndex--) {
            if (chr == source[rollIndex])
                return rollIndex;
        }

        return -1;
    }
}

Related

  1. lastIndexOf(char ch, String str)
  2. lastIndexOf(CharSequence chars, String searched)
  3. lastIndexOf(CharSequence charSeq, char ch)
  4. lastIndexOf(CharSequence cs, int searchChar, int start)
  5. lastIndexOf(CharSequence haystack, char needle)