Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The program below searches through a string and checks for a substring
- 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);
- }
- }
- }
- //Alternatively you could do the same thing with the help of strOrig.lastIndexOf(Stringname)
- public class HelloWorld{
- public static void main(String []args) {
- String t1 = "Tutorialspoint";
- int index = t1.lastIndexOf("p");
- System.out.println(index);
- }
- }
Add Comment
Please, Sign In to add comment