public class test44 { //分割字符串数组 public static String [] spitString ( String resource , String tag ){ return resource . split ( tag ); } } 测试public class test43 { public static void main ( String [] args ){ //String的index
//分割字符串数组
public static String[] spitString(String resource,String tag){
return resource.split(tag);
}
}
测试public class test43 {
public static void main(String[] args){
//String的indexof
String mail="javascript.com";
System.out.println("索引位置"+mail.indexOf('a'));
System.out.println("索引位置"+mail.indexOf('a',4));
System.out.println("索引位置"+mail.indexOf("co"));
//分割字符串方法
String target="歌谣,小白,小红,小花,小草,小黑";
String[] str=test44.spitString(target,",");
for(String s:str){
System.out.println(s);
}
//重载
String str1=target.substring(3);
System.out.println(str1);
String str2=target.substring(3,10);
System.out.println(str2);
}
}
运行结果