java indexof int,int indexOf(String str, int fromIndex)

int indexOf(String str, int fromIndex)

描述 (Description)

java.lang.String.indexOf(String str, int fromIndex)方法从指定索引处开始返回指定子字符串第一次出现的字符串中的索引。 返回的整数是最小值k,其中 -

k 》 = Math.min(fromIndex, this.length()) && this.startsWith(str, k)

如果不存在这样的k值,则返回-1。 。

声明 (Declaration)

以下是java.lang.String.indexOf()方法的声明public int indexOf(String str, int fromIndex)

参数 (Parameters)str - 这是要搜索的子字符串。

fromIndex - 这是开始搜索的索引。

返回值 (Return Value)

此方法返回指定子字符串第一次出现的字符串中的索引,从指定的索引开始。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.String.indexOf()方法的用法。package com.iowiki;

import java.lang.*;

public class StringDemo {

public static void main(String[] args) {

String str1 = "Collections of tutorials at tutorials point";

/* search starts from index 10 and if located it returns

the index of the first character of the substring "tutorials" */

System.out.println("index = " + str1.indexOf("tutorials", 10));

/* search starts from index 9 and returns -1 as substring "admin"

is not located */

System.out.println("index = " + str1.indexOf("admin", 9));

}

}

让我们编译并运行上面的程序,这将产生以下结果 -index = 15

index = -1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值