It seems parseDouble can accept strings with trailing spaces, but parseInt and parseLong throw an Exception.
e.g. For this test case
@Test
public void testNumberParsing() {
try {
Double.parseDouble("123.0 ");
System.out.println("works");
}catch (NumberFormatException e) {
System.out.println("does not work");
}
try {
Integer.parseInt("123 ");
System.out.println("works");
}catch (NumberFormatException e) {
System.out.println("does not work");
}
try {
Long.parseLong("123 ");
System.out.println("works");
}catch (NumberFormatException e) {
System.out.println("does not work");
}
}
The results are
works
does not work
does not work
Why the difference in behaviour? Is that intentional?