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);
}

}

猜你喜欢

转载自www.cnblogs.com/xingsir/p/11948814.html