String indexOf() Method in Java with EXAMPLE | java substring indexof
WhatisindexOf()MethodinJava?indexOf()MethodisusedtogetindexofthefirstoccurrenceofacriteriaspecifiedintheparametersoftheIndexOfmethod.Acommonscenariocanbewhenasystemadminwantstofindtheindexofthe‘@’characteroftheemailIdofaclientandthenwantstogettheremainingsubstring.Inthatsituation,IndexOfmethodcanbeused.JavaStringindexOf()SyntaxThesyntaxofJavaStringindexOf()Methodis:publicintindexOf(intcha)JavaindexOf()ParametersBelowaretheindexOf()JavaString[1]parameters:char–Usedtorepresentasinglecharacterv...
What is indexOf() Method in Java?indexOf() Method is used to get index of the first occurrence of a criteria specified in the parameters of the IndexOf method.
A common scenario can be when a system admin wants to find the index of the ‘@’ character of the email Id of a client and then wants to get the remaining substring. In that situation, IndexOf method can be used.
Java String indexOf() SyntaxThe syntax of Java String indexOf() Method is:
public int indexOf(int cha) Java indexOf() ParametersBelow are the indexOf() Java String[1] parameters:
char – Used to represent a single character value
str – Used to represent the string to search for
fromIndex – Used to represent the index position to start the search from
Java String indexOf() Return ValueThis indexOf() Java String method[2] returns the index within this string of the first occurrence of the specified character. It returns -1 if the character does not occur.
...