Reputation: 1680
I would expect the following code to throw a ParseException, but it is "2" can anyone explain this or is this a bug in the java implementation? I am running it on the most recent Oracle (1.7.0_05) and osx jvms.
try {
NumberFormat format = NumberFormat.getInstance(Locale.US);
Number number = format.parse("2 3");
System.out.println(number);
} catch (ParseException e) {
System.out.println("2 3 is not a valid number!");
}
Upvotes: 4
Views: 250
Reputation: 22692
That is the expected result.
According to the documentation, NumberFormat.parse does not necessarily use the entire string.
Rule #1 of java programming: always read the documentation!
Upvotes: 1