🌐
W3Schools
w3schools.com › java › ref_string_indexof.asp
Java String indexOf() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A · ❮ String Methods · Search a string for the first occurrence of "planet": String myStr = "Hello planet earth, you are a great planet."; System.out.println(myStr.indexOf("planet")); Try it Yourself » ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-indexof
Java String indexOf() Method - GeeksforGeeks
November 19, 2024 - // Java code to demonstrate the ... its index i.e. 11. ... This method returns the index of the first occurrence of the specified character by starting the search at the specified index....
Discussions

string - Implementing Java's indexOf method (Substring search) - Stack Overflow
I am only a second semester CS student and can't use any of the well known efficient substring search algorithms. I need to implement the indexOf method with the following method signature: int in... More on stackoverflow.com
🌐 stackoverflow.com
Find all index of occurrences of character in a string
Why would you even need the indexOf method? The naive, straightforward approach is to use .charAt and to loop over the characters in the string using a forloop. (TBH, .indexOf does exactly the same under the hood, just adds a starting index and it stops on the first occurrence). Honestly, the only way to learn proper programming is to stop searching for solutions and to sit down and try to work out your own solutions, because otherwise, you get in over your head, as in your case ending with code that you might have been able to somewhat reproduce, but that you don't understand. Start with pen(cil) and paper and try to figure out how you, the person, would address a problem. Only once you have found a solution start thinking about programming it. And don't memorize. Especially not code. Code adapts to the situation and is only the end product, not the starting point. Edit: Very mature move/s of you blocking people that offer help and advice to you just because you feel personally attacked or disagree with what has been said. More on reddit.com
🌐 r/learnjava
10
3
October 7, 2024
ArrayList indexOf not working
There are two errors with your code: Don't compare Strings with == answer is a String, but players will contain Player objects. So players.indexOf(answer) will never return a match. More on reddit.com
🌐 r/javahelp
4
2
October 16, 2022
Time complexity of String.Contains()
You need to understand how collections work... A string is an object but is also a collection of char structs. The IndexOf method returns the index in the array where the sequence of elements first match. Microsoft did something really smart here to reuse code, if a string contains an element/sequence it should also have an index, so they call the IndexOf method. If the method returns anything higher than -1 then it means that the collection does contain said sequence because it has an index. So to answer your question, look at the IndexOf method. More on reddit.com
🌐 r/csharp
25
1
July 16, 2020
🌐
CodeGym
codegym.cc › java blog › strings in java › java string indexof()
Java String indexOf()
December 26, 2024 - In conclusion, the indexOf() method in Java is a powerful tool to find the position of a character or a substring within a string.
🌐
TechVidvan
techvidvan.com › tutorials › string-indexof-method-in-java
Java String indexOf() Method with Examples - TechVidvan
May 6, 2025 - public class TechVidvan IndexOf{ public static void main(String args[]){ String s1="Indexof method is used "; int index1=s1.indexOf("is"); int index2=s1.indexOf("index"); System.out.println(index1+" "+index2); int index3 = s1.indexOf("is", 4); System.out.println(index3); int index4 = s1.indexOf('s'); System.out.println(index4); } } ... public class IndexOf { public static void main(String[] args) { String s1 = "Java is easy to learn"; int index = s1.indexOf("easy"); System.out.println("The index of substring "+index); } }
🌐
Programiz
programiz.com › java-programming › library › string › indexof
Java String indexOf()
To find the index of the specified substring within the string, indexOf() takes these two parameters: str - the string whose starting index is to be found · fromIndex (optional) - if fromIndex is passed, the str string is searched starting from this index · returns the index of the first ...
🌐
freeCodeCamp
freecodecamp.org › news › indexof-in-java-how-to-find-the-index-of-a-string-in-java
indexOf in Java – How to Find the Index of a String in Java
March 24, 2022 - If you're wondering how the index numbers are derived then you should note that the first character in a string has an index of zero, the second character has an index of one, and so on. Here's an example that explains the int indexOf(int char, int fromIndex) method:
🌐
FavTutor
favtutor.com › blogs › java-indexof
indexOf Method in Java (with Examples)
November 18, 2023 - The indexOf() method is a member of the String class in Java and is used to find the position of the first occurrence of a specified character or substring within a given string. It returns the index as an integer value, which represents the ...
🌐
Javatpoint
javatpoint.com › java-string-indexof
Java String.indexOf()
Java String indexOf() method with method signature and examples of concat, compare, touppercase, tolowercase, trim, length, equals, split, string indexof in java etc.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-indexof-method-example
Java String indexOf() Method
July 1, 2024 - public class StringIndexOfExample { public static void main(String[] args) { String str = "Hello, world!"; // Find the index of a character int index1 = str.indexOf('o'); System.out.println("Index of 'o': " + index1); // Output: 4 // Find the index of a character starting from the given index ...
🌐
Udemy
blog.udemy.com › home › it & development › software development › understanding the java string indexof method
Understanding the Java String IndexOf Method - Udemy Blog
April 14, 2026 - The Java string indexOf method is a function that is used to get the integer value of a particular index of String type object, based on a criteria specified in the parameters of the IndexOf method.
🌐
Tutorialspoint
tutorialspoint.com › java › java_string_indexof.htm
Java String indexOf() Method
This method returns the index within this string of the first occurrence of the specified character or -1, if the character does not occur. ... See the description. import java.io.*; public class Test { public static void main(String args[]) ...
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java string indexof method with code examples
Java String indexOf Method With Syntax & Code Examples
April 1, 2025 - As the name suggests, a Java String indexOf() method is used to return the place value or the index or the position of either a given character or a String.
🌐
How to do in Java
howtodoinjava.com › home › string › java string indexof()
Java String indexOf() with Examples - HowToDoInJava
January 10, 2023 - The indexOf() method is an overloaded method and accepts two arguments: substring or ch: the substring that needs to be located in the current string.
🌐
Baeldung
baeldung.com › home › java › java string › java string.indexof()
Java.String.indexOf() | Baeldung
April 11, 2025 - • Java String.indexOf() (current ... • Java String.valueOf() The method indexOf() returns the first occurrence index of a character or a String in another String....
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.string.indexof
String.IndexOf Method (Java.Lang) | Microsoft Learn
Returns the index within this string of the first occurrence of the specified substring. The returned index is the smallest value k for which: ... If no such value of k exists, then -1 is returned.
🌐
iO Flood
ioflood.com › blog › indexof-java
Java's String IndexOf Method: A Detailed Usage Guide
February 26, 2024 - The indexOf() method in Java is a part of the String class and is used to find the position of a character or substring in a string. The method returns the index within this string of the first occurrence of the specified character or substring.
🌐
Tutorial Gateway
tutorialgateway.org › java-indexof-method
Java indexOf string
April 13, 2016 - Java indexOf Method returns the index position of the first occurrence of a given string. If it is not found, the String.indexOf returns -1.
🌐
CodingBat
codingbat.com › doc › java-string-indexof-parsing.html
Java String indexOf Parsing
int indexOf(String target, int fromIndex) -- searches left-to-right for the target as usual, but starts the search at the given fromIndex. The fromIndex does not actually need to be valid. If it is negative, the search happens from the start of the string.
🌐
W3Resource
w3resource.com › java-tutorial › string › string_indexof.php
Java String: indexOf Method - w3resource
August 19, 2022 - The following example shows the usage of java String() method. public class Example { public static void main(String[] args) { String str = "The quick brown fox jumps over the lazy dog."; // Get the index of all the characters of the alphabet // starting from the beginning of the String. int a = str.indexOf("a", 0); int b = str.indexOf("b", 0); int c = str.indexOf("c", 0); int d = str.indexOf("d", 0); int e = str.indexOf("e", 0); int f = str.indexOf("f", 0); int g = str.indexOf("g", 0); int h = str.indexOf("h", 0); int i = str.indexOf("i", 0); int j = str.indexOf("j", 0); int k = str.indexOf("