📌  相关文章
📜  java代码示例中使用什么方法获取字符串中字符的索引位置

📅  最后修改于: 2022-03-11 14:52:28.758000             🧑  作者: Mango

代码示例2
// If you want to get the index position of a character in a String, use this method:
.charAt( /*Args int*/ )
// Here's a practial example:
String str = "Grepper";
char ch = str.charAt(0);

// If you want to get the index position of a word/char in a string(a Phrase/Sentence), you could use this method:
.indexOf( /*Args Str*/ )
// Here's a practial example:
String myStr = "This is just an example Sentence";
System.out.println(myStr.indexOf("example"));