Java String.lastIndexOf() – Java String.lastIndexOf()

最后修改: 2017年 11月 9日

中文/混合/英文(键盘快捷键:t)

The method lastIndexOf() returns the index of the last occurrence of a String in another String. If an int is passed to the method, then the method searches for the Unicode character equivalent.

方法lastIndexOf()返回一个字符串在另一个字符串中最后出现的索引。如果一个int被传递给该方法,那么该方法将搜索Unicode字符的等值。

We can also pass the index of the character to start searching from.

我们也可以传递字符的索引来开始搜索。

Available Signatures

可用的签名

public int lastIndexOf(int ch)
public int lastIndexOf(int ch, int fromIndex)
public int lastIndexOf(String str)

Example

示例

@Test
public void whenCallLastIndexOf_thenCorrect() {
    assertEquals(2, "foo".lastIndexOf("o"));
    assertEquals(2, "foo".lastIndexOf(111));
}
Next »

Java String.regionMatches()

« Previous

Java String.isEmpty()