更新時間:2022-05-20 13:01:45 來源:動力節(jié)點 瀏覽1576次
Java中如何進(jìn)行字符串查找?動力節(jié)點小編來告訴大家。
您可以使用 String 類的 indexOf() 方法在字符串中搜索特定字母。此方法返回字符串中單詞的位置索引(如果找到)。否則返回-1。
例子
public class Test {
public static void main(String args[]) {
String str = new String("hi welcome to Tutorialspoint");
int index = str.indexOf('w');
System.out.println("Index of the letter w :: "+index);
}
}
輸出
Index of the letter w :: 3
相關(guān)閱讀
0基礎(chǔ) 0學(xué)費 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請后,顧問老師會電話與您溝通安排學(xué)習(xí)
初級 202925
初級 203221
初級 202629
初級 203743