Here you can find the source of lastIndexOf(String string, String substring)
lastIndexOf
from String
class to make it work indepent of the platform used.
Parameter | Description |
---|---|
string | The String to search |
substring | The substring to be found inside <code>string</code> |
substring
in string
or -1
public static int lastIndexOf(String string, String substring)
//package com.java2s; //License from project: LGPL public class Main { /**//from ww w . j av a2s . c o m * Reimplementation of <code>lastIndexOf</code> from <code>String</code> * class to make it work indepent of the platform used. JavaME's String i.e. * does not provide this method. * * @param string The String to search * @param substring The substring to be found inside <code>string</code> * @return The index of the start of <code>substring</code> in <code>string</code> or -1 */ public static int lastIndexOf(String string, String substring) { int len = string.length(); while (len >= -1) { if (string.startsWith(substring, len)) { return len; } len--; } return len; } }