Java String Last Index Of lastIndexOf(String what, String within)

Here you can find the source of lastIndexOf(String what, String within)

Description

last Index Of

License

Open Source License

Declaration

public static int lastIndexOf(String what, String within) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 MATERNA Information & Communications. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html. For further
 * project-related information visit http://www.ws4d.org. The most recent
 * version of the JMEDS framework can be obtained from
 * http://sourceforge.net/projects/ws4d-javame.
 ******************************************************************************/

public class Main {
    public static int lastIndexOf(String what, String within) {
        if (what == null || within == null || what.length() == 0) {
            return -1;
        }/*ww  w.  ja  va  2 s .  co  m*/
        int i = 0;
        int lastI = -1;
        while ((i = within.indexOf(what, i)) != -1) {
            lastI = i++;
        }
        return lastI;
    }
}

Related

  1. lastIndexOf(String string, char value, int startIndex, int count)
  2. lastIndexOf(String string, char... chars)
  3. lastIndexOf(String string, String substring)
  4. lastIndexOf(String text, int startPos, String... searchStrings)
  5. lastIndexOf(String text, String key, int num)
  6. lastIndexOf(StringBuffer buf, String str)
  7. lastIndexOfAny(final String delimiters, final String str)
  8. lastIndexOfAny(String str, String search, int offset)
  9. lastIndexOfAnyBut(String srcString, String validString)