indexOf

indexOf,第1张

indexOf()字符位置

package seday01;

/**
* int indexOf(String str)
* 查找给定字符串在当前字符串中的位置,若返回值为-1,则
* 表示当前字符串中不含有给定的内容.
* @author xingsir
*
*/

public class IndexofDemo {

public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "thinking in java";
/*
* 第一次出现给定字符的位置
*/
int index = str.indexOf("in");
System.out.println(index);
/*
* 从指定位置开始检索第一次出现给定字符的位置
*/
index = str.indexOf("in", 3);
System.out.println(index);
/*
* 最后一次出现给定字符的位置
*/
index = str.lastIndexOf("in");
System.out.println("index:" + index);
}

}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/587581.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存