Tokenize problem in Java with separator ". "

Posted by user112976 on Stack Overflow See other posts from Stack Overflow or by user112976
Published on 2010-06-04T07:23:04Z Indexed on 2010/06/06 19:32 UTC
Read the original article Hit count: 409

I need to split a text using the separator ". ". For example I want this string :

Washington is the U.S Capital. Barack is living there.

To be cut into two parts:

Washington is the U.S Capital. 
Barack is living there.

Here is my code :

// Initialize the tokenizer
StringTokenizer tokenizer = new StringTokenizer("Washington is the U.S Capital. Barack is living there.", ". ");
 while (tokenizer.hasMoreTokens()) {
      System.out.println(tokenizer.nextToken());

}

And the output is unfortunately :

Washington
is
the
U
S
Capital
Barack
is
living
there

Can someone explain what's going on?

© Stack Overflow or respective owner

Related posts about java

Related posts about string