//目的:
// 定义字符串,使用split()方法对字符串进行拆分
//创建类
public class pre1 {
// 主方法
public static void main(String args[]) {
// 定义的字符串str
String str = new String("abc,def,ghi,gkl");
// 使用split()方法对字符串进行拆分,返回字符串数组
String[] newstr = str.split(",");
// 使用for循环遍历字符数组
for (int i = 0; i < newstr.length; i++) {
// 输出信息
System.out.println(newstr[i]);
}
System.out.println("第二次拆分");
// 对字符串进行拆分,并限定拆分字符段数,返回字符数组
String[] newstr2 = str.split("g", 3);
// 循环遍历字符数组
for (int j = 0; j < newstr2.length; j++) {
// 输出信息
System.out.println(newstr2[j]);
}
}
}