提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将字符串分解为单词
/* from 时 代 J a v a - nowjava.com*/ import java.util.StringTokenizer; public class Main { public static void main(String[] argv) { String aString = "word1 word2 word3"; StringTokenizer parser = new StringTokenizer(aString); while (parser.hasMoreTokens()) { System.out.println(parser.nextToken()); } } }