Java examples for Regular Expressions:Split
Use \\s+ to breaking a string into separate words
public class CountWords { public static void main(String[] args) {/* ww w. j a v a2s . c o m*/ String s = "this is a test 1 2 3 4."; String[] word = s.split("\\s+"); for (String w : word) System.out.println(w); } }