我需要使用分隔符拆分文本". "
。例如我想要这个字符串:
Washington is the U.S Capital. Barack is living there.
分成两部分:
Washington is the U.S Capital.
Barack is living there.
这是我的代码:
// 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());
}
不幸的是,输出是:
Washington
is
the
U
S
Capital
Barack
is
living
there
有人可以解释发生了什么吗?