String.split() 一个或多个空格分割字符串
原创
©著作权归作者所有:来自51CTO博客作者wx6289ced28e34b的原创作品,请联系作者获取转载授权,否则将追究法律责任
待分隔字符串
//分别间隔一个空格,两个空格,一个tab制表符
String str = "a b c d";
效果
//四种分隔符
String[] arr1 = str.split(" ");
String[] arr2 = str.split("s");
String[] arr3 = str.split("\t");
String[] arr4 = str.split("\\s+");
//打印
for (String s : arr1) {
System.out.print(s+",");
}
System.out.println("");
for (String s : arr2) {
System.out.print(s+",");
}
System.out.println("");
for (String s : arr3) {
System.out.print(s+",");
}
System.out.println("");
for (String s : arr4) {
System.out.print(s+",");
}