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!");
}
It is because
NumberFormat.parse(String)may not use the entire text for parsing. See here.