String.indexof(str)的用法

int indexOf(int ch)   返回指定字符在此字符串中第一次出现处的索引。 
int indexOf(int ch, int fromIndex) 从指定的索引开始搜索,返回在此字符串中第一次出现指定字符处的索引。 
int indexOf(String str) 返回第一次出现的指定子字符串在此字符串中的索引。 
int indexOf(String str, int fromIndex) 从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引。 

例如:
String name="Hi Mary, Mary quite contrary"; name.indexof("Mary") 

返回3,name.indexof("ddd") 返回-1
原文地址:https://www.cnblogs.com/carbs/p/2572638.html