Created
September 2, 2017 15:04
-
-
Save memish/1c0bfd63a702acd9a4ac38de9de92678 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IndexOfExample{ | |
public static void main(String args[]){ | |
String s1="this is index of example"; | |
//passing substring | |
int index1=s1.indexOf("is");//returns the index of is substring | |
int index2=s1.indexOf("index");//returns the index of index substring | |
System.out.println(index1+" "+index2);//2 8 | |
//passing substring with from index | |
int index3=s1.indexOf("is",4);//returns the index of is substring after 4th index | |
System.out.println(index3);//5 i.e. the index of another is | |
//passing char value | |
int index4=s1.indexOf('s');//returns the index of s char value | |
System.out.println(index4);//3 | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment