split函数就是用于按指定字符或者字符串来分割一个字符串,然后返回字符串数组。
public class Test {
public static void main(String []args) {
String str1 = "123|456|789|abc";
String str2 = "zxcAvbnAasd";
//str1这里是用特殊字符为标记来分割的,所以需要有两个反斜杠来转义 "|"
//特殊字符有: | , + , * , ^ , $ , / , | , [ , ] , ( , ) , - , . , \
String[] split1 = str1.split("\\|");
String[] split2 = str2.split("A");
System.out.println("split1--"+split1[0]+","+split1[1]+","+split1[2]);
System.out.println("split2--"+split2[0]+","+split2[1]+","+split2[2]);
}
}
大概就这样了