- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Search for a character from a given position in Java
Use the indexOf() method to search for a character from a given position.
Let’s say the following is our string.
String myStr = "Amit Diwan";
Here, we are searching for the character “i” in the string. We are beginning the index from 4 for our search.
int begnIndex = 4; System.out.println("String: "+myStr); strLastIndex = myStr.indexOf('i', begnIndex);
The following is the complete example.
Example
public class Demo { public static void main(String[] args) { String myStr = "Amit Diwan"; int strLastIndex = 0; int begnIndex = 4; System.out.println("String: "+myStr); strLastIndex = myStr.indexOf('i', begnIndex); System.out.println("The index of character a in the string beginning from index "+begnIndex+" ="+strLastIndex); } }
Output
String: Amit Diwan The index of character a in the string beginning from index 4 = 6
- Related Articles
- Search index of a character in a string in Java
- How to search for ^ character in a MySQL table?
- Java program to extract ‘k’ bits from a given position
- Java Program to Get a Character From the Given String
- Java Program to remove a character at a specified position
- How can I search a character or substring in java?
- Java Program to search for a Substring from a specified index
- How to find the unicode category for a given character in Java?
- Java program for removing n-th character from a string
- MySQL Regex to match a pattern for ignoring a character in search like Chris.Brown?
- Search for a value in Java Decade Tuple
- Search for a value in Java KeyValue Tuple
- Search for a value in Java Octet Tuple
- Search for a value in Java LabelValue Tuple
- How to match a character from given string including case using Java regex?

Advertisements