Monster-su

int indexOf(String str)

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

相关解释

  • 函数数名:indexOf
  • 调用方式:Object(String).indexOf(String str,int startIndex)或String.indexOf(String str)
  • 参数说明:str需要查找的字串.
  • 查找说明:
    startIndex 从指定的索引处开始查询,if (startIndex<0),则在程序执行中认为startIndex=0;
    if(startIndex>Object.length) 则它被当作最大的可能索引。then 正常查询。
  • 返回内容:if (在Object中查找到字串)返回字串第一次出现的索引
    if(在Object中没有查找到字串) return -1
  • 返回值类型:int
  • example:
public class LookSubstring
{
 public static void main(String[] args)
 {
     //define a known String
  String str="assfdsffeffeffds";
  //define a substring
  String sustr="ff";
  System.out.println(str.indexOf(sustr));
  System.out.println(str.indexOf(sustr,8));
 }

}

int lastIndexOf(String str)

返回在此字符串中最右边出现的指定子字符串的索引。
int lastIndexOf(String str, int startIndex) :从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。

分类:

技术点:

相关文章:

  • 2021-12-27
  • 2021-05-19
  • 2022-12-29
  • 2021-09-11
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-26
  • 2021-11-18
  • 2022-12-23
  • 2021-09-28
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案