S.split(s) 表示将字符串S按照s截开,对于空白字符String str = "a b c d";
String[] arr1 = str.split(" "); //仅分割一个空格
String[] arr2 = str.split("s");
String[] arr3 = str.split("\t"); //空格
正则表达式\s表示匹配任何空白字符,+表示匹配一次或多次
String[] arr4 = str.split("\s+"); //分割一个或者多个空格
import java.util.*;
public class Main{
static int N = 1010;
static String[] s = new String[1010];
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
str = str.substring(0, str.length() - 1); //删除最后一个"."
s = str.split("\\s+");
for (String t: s) {
System.out.print(t.length() + " ");
}
}
}
标签:String,scan,空格,static,split,str
From: https://www.cnblogs.com/sherkevin/p/16590981.html