I will leave a note of what I learned while practicing JAVA.
Get the index number by specifying one character in the character string
Simply put, "I" in the "Hello" or has entered into any position! ?? It is a rudimentary problem during the rudimentary process.
You can get the index by using the " .indexOf
"method on the string.
JAVA code
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
//Declare a string
String str = "Hello JAVA";
//Get index number
System.out.println("The index number is:"+str.indexOf("Hmm"));
}
}
output
The index number is:1
Now you can get the index number 1 of "n".
Recommended Posts