Home Java String-examples String indexOf(int ch, int fromIndex)



String indexOf(int ch, int fromIndex)
Posted on: August 21, 2007 at 12:00 AM
In this section, you will get the detailed explanation about the indexOf(int ch, int fromIndex) method of String class.

String indexOf(int ch, int fromIndex)

     

In this section, you will get the detailed explanation about the indexOf(int ch, int fromIndex) method of String class. We are going to use indexOf(int ch, int fromIndex) method of String class in Java. The description of the code is given below for the usage of the method.

Description of the code:

Here, you will get to know about the
indexOf(int ch, int fromIndex) method through the following java program. In the program code given below, we have taken a String. To find the index of any character in a string we have applied indexOf(int ch, int fromIndex); method and then we have passed the character from a string in that with the index number to find its index starting from the specified index as shown in the output. You must be observing in the output that we have also taken the ASCII value of small "b" which is 98 with the index number. Hence its also giving the same result.

NOTE: This method returns the index of the first occurrence of the given character, starting the search at the specified index within the string.

Here is the code of the program:

public class IndexOfChar{
  public static void main(String args[]) {
  String s = "Honesty is the best Policy";
  System.out.println(s);
  System.out.println("indexOf(n, 1) -> " + s.indexOf('b'1));
  System.out.println("indexOf(n, 1) -> " + s.indexOf(981));
  }
  }

Output of the program:

C:\unique>java IndexOfChar
Honesty is the best Policy
indexOf(n, 1) -> 15
indexOf(n, 1) -> 15

C:\unique>

Download this example.

Related Tags for String indexOf(int ch, int fromIndex):
javacstringmethodsedoutputfindgetcharnumberinttarappcharacterstartshowifindexiectewithprogramtoramssecisheilitliputpeindexoffromartinnopassasstamntouttrminminjspecthroughmehowhrproppsspstaratanyrackhallivfollowandaractcodcodestrrtwingvassriringthshoavbelostabaphatfinplprmindmindodeomogrolo


More Tutorials from this section

Ask Questions?    Discuss: String indexOf(int ch, int fromIndex)  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.