使用正则表达式按空格分割字符串
public class Main {/** 来 自 时代Java**/ private String jaText = "this is a test "; public Main() { String[] fields = jaText.split("\\s", 3); for (String field : fields) { System.out.printf("Split: %s\n", field); } } }
public class Main {/** 来 自 时代Java**/ private String jaText = "this is a test "; public Main() { String[] fields = jaText.split("\\s", 3); for (String field : fields) { System.out.printf("Split: %s\n", field); } } }