is there a way to find if the value parsed and returned by java.io.StreamTokenizer.nval (e.g. 200
) was an integer or a floating number ?
Thanks
Edited:
I want to be able to know if the input was '200' or '200.0'.
I don't think it is possible with StringTokenizer, it's too old. You can use Scanner to do the job:
Scanner fi = new Scanner("string 200 200.0");
fi.useLocale(Locale.US);
while (fi.hasNext()) {
if (fi.hasNextInt()) {
System.out.println("Integer: " + fi.nextInt());
} else if (fi.hasNextDouble()) {
System.out.println("Double: " + fi.nextDouble());
} else {
System.out.println("String: " + fi.next());
}
}
Documentation for the class is here