Java String Index Of lastIndexOf(String pattern, String s)

Here you can find the source of lastIndexOf(String pattern, String s)

Description

last Index Of

License

Apache License

Declaration

public static int lastIndexOf(String pattern, String s) 

Method Source Code

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

import java.util.List;

public class Main {
    public static final String EMPTY_STRING = "";

    public static int lastIndexOf(String pattern, String s) {

        if (!isNullOrEmpty(s)) {
            int pos = s.indexOf(pattern);

            while (pos != -1) {

                if ((pos + 1) >= s.length())
                    return pos;

                int newPos = s.substring(pos + 1).indexOf(pattern);

                if (newPos > 0) {
                    pos = newPos + 1 + pos;
                } else {
                    return pos;
                }// ww w  .  j  a va  2  s.c o  m
            }

        }

        return -1;
    }

    public static boolean isNullOrEmpty(String[] s) {

        if ((s == null) || (s.length == 0))
            return true;

        for (int i = 0; i < s.length; i++) {

            if (!isNullOrEmpty(s[i])) {
                return false;
            }
        }

        return true;
    }

    public static boolean isNullOrEmpty(List<String> input) {
        return (input == null) ? true : isNullOrEmpty(input.toArray(new String[input.size()]));
    }

    public static boolean isNullOrEmpty(String s) {
        return (s == null) || s.equals(EMPTY_STRING);
    }
}

Related

  1. indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex)
  2. indexOfIgnoreCase(String str, String substring)
  3. indexOfMultiple(String line, char character, int count, int startIndex)
  4. indexOfWord(String word, String string)
  5. isPhaseGroupContainsPhase(int index, String phaseName)
  6. lastIndexOfIgnoreCase(final String s, final String subS)
  7. mergeStringLines(String lineOne, String lineTwo, int keyIndex, int insertingIndex)
  8. readColumn(int columnIndex, String inputString, String columnSeparator)
  9. removeColumn(String line, int index)