Specify a regular expression to match one or more spaces
public class Main { public static void main(String args[]) throws Exception {
String s3 = "A BB CCC";
String[] words = s3.split("\\s+"); for (String str : words) {
System.out.println(str);
}
}
}
/*
A
BB
CCC
*/