package font_files;
public class SearchLastString {
public static void main(String[] args) {
String randomword = "nice is good, and I like nicessss, do you like?";
String love ="nice";
int location = randomword.lastIndexOf(love);
if (location==-1){
System.out.println("Not find!");
}else {
System.out.println("randomword is located in " + location);
}
}
}
结果为:
randomword is located in 25
可以看出,这个lastIndexOf()函数只是找到相同的字符段就行了,不管是不是相同的单词。
package font_files;
public class SearchLastString {
public static void main(String[] args) {
String randomword = "nice is good, and I like neicessss, do you like?";
String love ="nice";
int location = randomword.lastIndexOf(love);
if (location==-1){
System.out.println("Not find!");
}else {
System.out.println("randomword is located in " + location);
}
}
}
结果为:
randomword is located in 0
这个查找是从0 开始的。