欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

indexOf跟substring的用法,indexofsubstring

来源: javaer 分享于  点击 31737 次 点评:174

indexOf跟substring的用法,indexofsubstring


实例
下面的示例演示使用的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 s
System.out.println("index of letter 's' = " 
+ str.indexOf('s')); 

// returns -1 as character e is not in the string
System.out.println("index of letter 'e' = " 
+ str.indexOf('e'));

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

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

相关文章

    暂无相关文章

用户点评