🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-indexof
Java String indexOf() Method - GeeksforGeeks
November 19, 2024 - // Java code to demonstrate the ... ch) public class Index1 { public static void main(String args[]) { String s = new String("Welcome to geeksforgeeks"); System.out.print("Found g first at position: "); System.out.println(s.indexOf('g')); } } ... In the ...
🌐
W3Schools
w3schools.com › java › ref_string_indexof.asp
Java String indexOf() Method
HTML Certificate CSS Certificate JavaScript Certificate Front End Certificate SQL Certificate Python Certificate PHP Certificate jQuery Certificate Java Certificate C++ Certificate C# Certificate XML Certificate ... W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
🌐
FavTutor
favtutor.com › blogs › java-indexof
indexOf Method in Java (with Examples)
November 18, 2023 - The indexOf method first finds the index of the substring "Java '' within the sentences. To find subsequent occurrences, the method is called again, providing the starting index as first Index + 1, ensuring the search begins after the first occurrence. These examples illustrate how indexOf efficiently identifies the index of specific elements or substrings within strings and how it can be used to handle multiple occurrences.
🌐
TechVidvan
techvidvan.com › tutorials › string-indexof-method-in-java
Java String indexOf() Method with Examples - TechVidvan
May 6, 2025 - The indexof() method searches the supplied Substring beginning at the beginning of the string.
🌐
Programiz
programiz.com › java-programming › library › string › indexof
Java String indexOf()
// Java String indexOf() with only one parameter class Main { public static void main(String[] args) { String str1 = "Learn Java"; int result; // getting index of character 'J' result = str1.indexOf('J'); System.out.println(result); // 6 // the first occurrence of 'a' is returned result = ...
🌐
Codecademy
codecademy.com › docs › java › strings › .indexof()
Java | Strings | .indexOf() | Codecademy
May 13, 2022 - The .indexOf() method returns the zero-indexed position of the first occurrence of the given character(s) in a string. It returns -1 if the given characters(s) are not found. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more! ... Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
🌐
CodeGym
codegym.cc › java blog › strings in java › java string indexof()
Java String indexOf()
December 26, 2024 - We repeat this process until indexOf() returns -1, indicating that there are no more occurrences of the character in the string. In this example, we found that the character 'o' appears at positions 4 and 8 in the string "Hello, world!". Suppose ...
🌐
Baeldung
baeldung.com › home › java › java string › java string.indexof()
Java.String.indexOf() | Baeldung
April 11, 2025 - A quick example and explanation of the indexOf API of the standard String class in Java.
Find elsewhere
🌐
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 - This is the simplest form of the Java indexOf() method. In this example, we are taking an input String in which we are going to find the index of a substring that is a part of the main String.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › indexof() java method explained [easy examples]
IndexOf() Java Method Explained [Easy Examples] | GoLinuxCloud
September 8, 2021 - The IndexOf() Java method is really helpful in practical cases. For example, let us say we have a list of items to buy from the shop and we just wanted to know if we had added bananas to our list or not.
🌐
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 - In the first example below, we'll find the index of a single character in a string. This example will help us understand the public int indexOf(int char) method.
🌐
GeeksforGeeks
geeksforgeeks.org › java › list-indexof-method-in-java-with-examples
List indexOf() Method in Java with Examples - GeeksforGeeks
November 29, 2024 - Example: Java · // Java Program ... l.add("Geeks"); l.add("for Geeks"); l.add("GFG"); // Index Of System.out.println("Index of GFG is " + l.indexOf("GFG")); } } Output ·...
🌐
Career Karma
careerkarma.com › blog › java › java indexof(): a how-to guide
Java indexOf(): A How-To Guide: A Tutorial | Career Karma
December 1, 2023 - To accomplish this task, we could use the indexOf() method. Here’s an example that searches for the Java string Strawberry in our list of fruits.
🌐
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.
🌐
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 following example demonstrates Java String indexOf method overload that takes one string type variable as parameter and the other integer type indexfrom variable and returns the starting index of that string after the specified index:
🌐
How to do in Java
howtodoinjava.com › home › string › java string indexof()
Java String indexOf() with Examples - HowToDoInJava
January 10, 2023 - In the following example, we check if the substring “World” exists in the given string. If it exists, at what index is the substring present? The substring is found at the index position 6, and the indexOf() method returns 6.
🌐
Medium
medium.com › @AlexanderObregon › javas-arraylist-indexof-method-explained-6bb47ce4c894
Java’s ArrayList.indexOf() Method Explained | Medium
August 19, 2024 - This example demonstrates how indexOf() can be used to search for specific configuration values within a list. The method successfully finds the position of "timeout=5000" and returns its index.
🌐
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. If it does not occur as a substring, -1 is returned. Let’s take a look at a basic example ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-util-arraylist-indexof-java
Java Arraylist indexOf() Method - GeeksforGeeks
December 10, 2024 - Example 2: Here, we use the indexOf() method to find the first occurrence and lastIndexOf() to find the last occurrence of a specific element. ... // Java program to demonstrate the use of // indexOf() and lastIndexOf() methods import ...