Java字符串lastIndexOf()方法示例。
String类的lastIndexOf()方法接受一个String作为参数,如果该字符串参数在该对象中作为子字符串出现一次或多次,则它将返回最后一个此类子字符串的第一个字符的索引。如果它不是作为子字符串出现,则返回-1。
示例
import java.io.*;
public class Test {
public static void main(String args[]) {
String Str = new String("Welcome to Nhooo.com");
String SubStr1 = new String("Tutorials" );
System.out.print("找到最后一个索引:" );
System.out.println( Str.lastIndexOf( SubStr1 ));
}
}输出结果
找到最后一个索引:11