Java indexOf() & lastIndexOf() Method
The String indexOf() method is used to searches for the first occurrence of a character value. The index count starts from zero.
Syntax:
public int indexOf(int ch)
Example:
public class IndexOf{
public static void main(String args[])
{
String s1="Welcome to Programtpoint";
int s2=s1.indexOf('e');
System.out.println(s2);
}
}
Java lastIndexOf() Method
The String lastIndexOf() method is used to searches for the last occurrence of a character value. The index count starts from zero.
Syntax:
public int lastIndexOf(int ch)
Example:
public class LastIndexOf
{
public static void main(String args[])
{
String s1="Welcome to Onlinetpoint";
int s2=s1.lastIndexOf('e');
System.out.println(s2);
}
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com