aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes parse & valueOf Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "parse & valueOf" Watch "parse & valueOf" New topic
Author

parse & valueOf

sonali rao
Ranch Hand

Joined: Nov 03, 2003
Posts: 64
parsexxx method accepts String arguements with a suffix of f,F,d,D but not l,L.
same is the case with valueOf().
Am i right? [ I hope my question is clear]
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
It depends which class method parseXXX is invoked as per API. Float and Double require that the string parameter contain decimals only, otherwise, a NumberFormatException will be thrown at runtime.
Integral wrappers (Byte, Short, Integer, and Long) are less restrictive. They provide overloaded parseXXX and valueOf methods that accept radix as a second argument. The parsable string must contain only digits of the specified radix base. The radix argument is usually one of (2,8,10,16).
So, the allowed digits for radix 2 are 0 and 1; for radix 8: 0-7; for radix 16: 0-F.
However, you can provide your own radix in case you're up to this sport:

valueOf works exactly the same way as parseXXX. parseXXX taking one argument assumes that the base is 10, so the only allowed digits are 0-9.
Letters L, X, and l are not allowed as part of the string at runtime as they are normally not digits of any normal radix base (you can go fancy though).
[ November 11, 2003: Message edited by: Vad Fogel ]
Harwinder Bhatia
Ranch Hand

Joined: Oct 17, 2003
Posts: 150
Sonali
I guess what you are referring to is parseType (String) and valueOf (String) methods:


Any String argument that does not follow the above rules result in
a NumberFormatException at run-time !!
Cheers
Harwinder
[ November 12, 2003: Message edited by: Harwinder Bhatia ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parse & valueOf
 
Similar Threads
copyValueOf vs ValueOf
How to pass a long in ...Long ll = Long.valueOf(3L);//gives
Clarify... Wrapper Classes...
throws NumberFormatException ???
conditional operater?