Java: Get the first occurrence of a string within a given string
First Occurrence in String
Write a Java program to get the first occurrence (Position starts from 0.) of a string within a given string.
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
1
Flowchart:
For more Practice: Solve these Related Problems:
- Modify the program to return the last occurrence of the substring.
- Write a program to count the number of times a substring appears.
- Modify the program to find the index of the first occurrence of any of multiple substrings.
- Write a program to check if a string contains only unique characters.
Go to:
PREV : Square Root Calculation.
NEXT : First Occurrence in Array.
Java Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.