Skip to content

Instantly share code, notes, and snippets.

@memish
Created September 2, 2017 15:04
Show Gist options
  • Save memish/1c0bfd63a702acd9a4ac38de9de92678 to your computer and use it in GitHub Desktop.
Save memish/1c0bfd63a702acd9a4ac38de9de92678 to your computer and use it in GitHub Desktop.
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