indexOf跟substring的用法

来源:互联网 发布:新概念 知乎 编辑:程序博客网 时间:2024/04/30 06:29

实例
下面的示例演示使用的java.lang.String.indexOf()方法

package com.yiibai;

import java.lang.*;

public class StringDemo {

public static void main(String[] args) {

String str = "This is yiibai";// returns the index of occurrence of character sSystem.out.println("index of letter 's' = " + str.indexOf('s')); // returns -1 as character e is not in the stringSystem.out.println("index of letter 'e' = " + str.indexOf('e'));

}
}
让我们来编译和运行上面的程序,这将产生以下结果:

index of letter ‘s’ = 3
index of letter ‘e’ = -1

0 0
原创粉丝点击