Sponsered Links
Categories
Sponsered Links

String class IndexOf method example

 

This is a simple String class IndexOf method example, in which method returns index location or number position of the specified character for a word or sequence of charaters, method returns the index location of letter with which the word starts.

public class StringIndex {
  public static void main(String args[]){
    
   
    String str = "jsp servlet tutorial";
    int str1= str.indexOf('h'),

str;
    
    System.out.println("Index of 'j' in String 'str' is: " +
str1);    
    System.out.println("Index of 's' in String 'str' is: " + str.indexOf("s"));
        
   
    System.out.println("Index of 'servlet' in String 'str' is: " + str.indexOf("

servlet"));
      
  }
}

 

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved