StreamTokenizer已过时,最好使用Scanner,这是您的问题的示例代码:
String s = "$23.24 word -123"; Scanner fi = new Scanner(s); //anything other than alphanumberic characters, //comma, dot or negative sign is skipped fi.useDelimiter("[^\p{Alnum},\.-]"); while (true) { if (fi.hasNextInt()) System.out.println("Int: " + fi.nextInt()); else if (fi.hasNextDouble()) System.out.println("Double: " + fi.nextDouble()); else if (fi.hasNext()) System.out.println("word: " + fi.next()); else break; }如果要使用逗号作为浮点定界符,请使用
fi.useLocale(Locale.FRANCE);



