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的indexofString 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);}
}
运行结果