溫馨提示×

java的indexof方法怎么使用

小億
93
2023-12-27 21:40:15
欄目: 編程語言

Java中indexOf方法用于查找指定字符串在字符串中第一次出現的位置。它的使用方式如下:

int indexOf(String str)

其中,str為要查找的字符串。

示例代碼:

String str = "hello world";
int index = str.indexOf("o");
System.out.println("第一次出現的位置:" + index);

輸出結果為:

第一次出現的位置:4

注意:返回的位置是從0開始計算的,如果要查找的字符串不存在,則返回-1。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女