programming-examples/java/Basics/How to search last occurance of a substring inside a substring.java

12 lines
399 B
Java
Raw Normal View History

2019-11-18 14:44:36 +01:00
public class SearchlastString {
public static void main(String[] args) {
String strOrig = "Hello world ,Hello Reader";
int lastIndex = strOrig.lastIndexOf("Hello");
if(lastIndex == - 1) {
System.out.println("Hello not found");
} else {
System.out.println("Last occurrence of Hello
is at index "+ lastIndex);
}
}
}