Tutorials

Java String Methods


String indexOf() method


In java, String indexOf( ) method returns the index of the input char, int or substring. In case the required char, int or substring is not found -1 is returned.

 

Example:


public class IndexOfDemo {

        public static void main(String[] args) {

               String str = "This is java tutorial";

               int index = str.indexOf('j');
               int index1 = str.indexOf("ava");
               int index2 = str.indexOf("is",4);

               System.out.println("index"+ index + index1+ index2);
               }
}


Please Share this page
Views : 76
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!