File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes confusion in parseDouble and parseInt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "confusion in parseDouble and parseInt" Watch "confusion in parseDouble and parseInt" New topic

confusion in parseDouble and parseInt

Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256
hi i am a bit stumped on why
Double.parseDouble(" 244") gives me 244 as output and
Integer.parseInt(" 244") gives NumberFormatException at runtime.

following is sample code

can anyone please explain???

Life called,so here I am.<br />Cheers<br />Niki.:-)
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
parseDouble() trims the white space, parseInt() does not.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The documentation for the standard Java API should be your first resource when encountering such questions. Find the docs for the version of Java you are using and bookmark them. Learn to navigate it so you can find these odd idiosyncracies between similar methods and other invaluable information about the classes and methods that are available.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: confusion in parseDouble and parseInt
It's not a secret anymore!