Use \\s+ to breaking a string into separate words - Java Regular Expressions

Java examples for Regular Expressions:Split

Description

Use \\s+ to breaking a string into separate words

Demo Code

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);

  }
}

Related Tutorials