🌐
W3Schools
w3schools.com › java › ref_string_indexof.asp
Java String indexOf() Method
String myStr = "Hello planet earth, you are a great planet."; System.out.println(myStr.indexOf("planet")); ... The indexOf() method returns the position of the first occurrence of specified character(s) in a string.
🌐
Medium
medium.com › @Neelesh-Janga › q-28-leetcode-find-the-index-of-the-first-occurrence-in-a-string-using-java-c56628b2d33c
Q-28 LeetCode: Find the Index of the First Occurrence in a String using Java
December 9, 2023 - Examples: 1. Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. 2. Input: haystack = "leetcode", needle = "leeto" Output: -1 Explanation: "leeto" ...
🌐
LeetCode
leetcode.com › problems › find-the-index-of-the-first-occurrence-in-a-string
Find the Index of the First Occurrence in a String - LeetCode
Find the Index of the First Occurrence in a String - Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
🌐
AlgoMonster
algo.monster › liteproblems › 28
28. Find the Index of the First Occurrence in a String - In-Depth Explanation
In-depth solution and explanation for LeetCode 28. Find the Index of the First Occurrence in a String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 0000-0099 › 0028.Find the Index of the First Occurrence in a String › README_EN.md
leetcode/solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md at main · doocs/leetcode
Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. ... Input: haystack = "leetcode", needle = "leeto" Output: -1 Explanation: "leeto" did not ...
Author   doocs
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-indexof
Java String indexOf() Method - GeeksforGeeks
November 19, 2024 - ... // Java code to demonstrate the working of String indexOf(char ch, int strt) public class Index2 { public static void main(String args[]) { String s = new String("Welcome to geeksforgeeks"); System.out.print( "Found g after 13th index at ...
🌐
TutorialKart
tutorialkart.com › java › get-the-index-of-first-occurrence-of-a-substring-in-a-string-using-java
How to get the index of first occurrence of a substring in a String using Java ?
May 4, 2023 - In this Java tutorial, you will learn how to find the index of first occurrence of a search string in a given string using String.indexOf() function, with examples.
🌐
Medium
medium.com › @AlexanderObregon › solving-the-find-the-index-of-the-first-occurrence-in-a-string-problem-on-leetcode-a-java-a75bd406c1fc
Solving the ‘Find the Index of the First Occurrence in a String’ on LeetCode: Java Solutions…
February 1, 2024 - The KMP Algorithm is the most efficient approach for finding the index of the first occurrence of a substring in a string, due to its optimal time complexity, although it uses a bit more space compared to other methods.
Find elsewhere
🌐
Substack
alexanderobregon.substack.com › p › leetcode-28-find-the-index-of-the
LeetCode #28: Find the Index of the First Occurrence in a String — Solved in Java
October 24, 2025 - Thinking through a solution in Java starts with how string comparison works at the character level. Every character can be read directly with charAt, which lets you match needle against slices of haystack without creating new strings. The simplest way is to slide one index through the text and check for a match at every position, which helps build an understanding of how pattern matching works mechanically.
🌐
Baeldung
baeldung.com › home › java › java string › java string.indexof()
Java.String.indexOf() | Baeldung
April 11, 2025 - • Java String.indexOf() (current article)• Java String.intern() • Java String.isEmpty() • Java String.lastIndexOf() • Java String.regionMatches() • Java String.replace() • Java String.replaceAll() • Java String.split() • Java String.startsWith() • Java String.subSequence() • Java String.substring() • Java String.toLowerCase() • Java String.toUpperCase() • Java String.trim() • Java String.valueOf() The method indexOf() ...
🌐
GitHub
github.com › LeetCode-Feedback › LeetCode-Feedback › issues › 24614
Missing Test Case - 28. Find the Index of the First Occurrence in a String · Issue #24614 · LeetCode-Feedback/LeetCode-Feedback
October 5, 2024 - Find the Index of the First Occurrence in a String#24614 ... take input of sub-string here depicted as "needle" take input of super-string here depicted as "haystack" check index of sub-string the super_string use indexOf function ... import ...
Published   Oct 05, 2024
🌐
TutorialsPoint
tutorialspoint.com › get-the-index-of-the-first-occurrence-of-a-separator-in-java
Get the index of the first occurrence of a separator in Java
public class Demo { public static ...Separator's first occurrence: "+sepPos); } } String: Tom-Hank-s Separator's first occurrence: 3 ... PHP – iconv_strpos() function – Find the position of the first occurrence of a needle in a haystack...
🌐
NamasteDev
namastedev.com › home › mathematical foundations › algorithms and data structures › find index of first occurrence in string
Find Index of First Occurrence in String - NamasteDev Blogs
July 16, 2025 - int strStr(string haystack, string needle) { int n = haystack.length(); int m = needle.length(); for(int i = 0; i <= n - m; i++) { int j = 0; for(j = 0; j < m; j++) { if(haystack[i + j] != needle[j]) { break; } } if(j == m) { return i; } } return -1; }
🌐
Cscode
cscode.io › algo › strings › FindTheIndexOfTheFirstOccurrenceInAString
Strings - Find The Index of The First Occurrence in a String | Java | CsCode.io
Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0.
🌐
Medium
medium.com › @rutujakbhombe19 › leetcode-28-find-the-index-of-the-first-occurrence-in-a-string-03f36240f6bd
Leetcode 28: Find the Index of the First Occurrence in a String | by Rutuja Bhombe | Medium
August 11, 2024 - Input: haystack = "sadbutsad", needle = "sad" Output: 0 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. ... Input: haystack = "leetcode", needle = "leeto" Output: -1 Explanation: "leeto" did not ...