GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Java String indexOf() Method - GeeksforGeeks Java String indexOf() MethodLast Updated : 19 Nov, 2024 In Java, the String indexOf() method returns the position of the first occurrence of the specified character or string in a specified string. In this article, we will learn various ways to use Example: Below is the simplest way that returns the index of the first occurrence of a specified character in a string, or -1 if the character does not occur.
Output Found g first at position: 11 Explanation: In the above example, it finds the first occurrence of the character Table of Content Different Variants of indexOf() Method in JavaThere are 3 variants of the indexOf() method are mentioned below: 1. indexOf(char ch, int strt)This method returns the index of the first occurrence of the specified character by starting the search at the specified index. Example:
Output Found g after 13th index at position: 19 2. indexOf(String str)This method returns the index of the first occurrence of the specified substring in the string. Example:
Output Found geeks starting at position: 11 3. indexOf(String str, int strt)This method returns the index of the first occurrence of the specified substring by starting the search at the specified index. Example:
Output Found geeks(after 14th index) starting at position: 19 Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |