String str = "java search string";
int firstIndex = str.indexOf("java");
System.out.println("First occurrence of char "+
" is found at : " + firstIndex);
int lastIndex = str.lastIndexOf("java");
System.out.println("Last occurrence of char java is"+
" found at : " + lastIndex);
int first_in = str.indexOf("java", 10);
System.out.println("First occurrence of char java"+
" after index 10 : " + first_in);
int last_in = str.lastIndexOf("java", 20);
System.out.println("Last occurrence of char java " +
"after index 20 is : " + last_in);
}
}
No comments:
Post a Comment