indexOf实际试用方法

用于搜索和查找关键字个数或者位置

 

 

例如:

package zifu;

public class tianqi {
public static void main (String args[]){
String a="昨天今天明天";
int s=a.indexOf("天",1);
System.out.println(s);
int s1=a.indexOf("天",s+1);
System.out.println(s1);

例如:

package zifu;

public class shi {
public static void main (String args[]){
String s="家事国事天下事事事关心";
int n=-1;
int p=5;
String key="事";
for(int i=0;i<=p;i++)
{
n=s.indexOf(key,n+1);
System.out.println(n);
}
}

}

posted @ 2016-05-10 20:30  我真的看不懂  阅读(288)  评论(0)    收藏  举报