字符串截取
字符串截取方法
splist()方法,将字串切割为若干部分,返回值为一个字符串数组.()里面其实是一个正则表达式.
注意,如果要按照.切分需要两个(反斜杠)
代码示例
public class Demo03 {
public static void main(String[] args) {
String str1 = "abc,def,ghi";
String arr1[] = str1.split(",");
for (int i = 0; i < arr1.length; i++) {
System.out.println(arr1[i]);
}
System.out.println("===================");
String str2 = "abc def ghi";
String arr2[] = str2.split(" ");
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
}
System.out.println("===================");
String str3 = "abc.abc.abc";
String arr3[] = str3.split(".");
System.out.println(arr3.length);
for (int i = 0; i < arr3.length; i++) {
System.out.println(arr3[i]);
}
System.out.println("===================");
String str4 = "VVV.VVV.VVV";
String arr4[] = str4.split("\\.");//需要两个\\
System.out.println(arr4.length);
for (int i = 0; i < arr4.length; i++) {
System.out.println(arr4[i]);
}
}
}
标签:abc,String,截取,System,println,length,字符串,out
From: https://www.cnblogs.com/harper886/p/17334282.html