File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes valueOf() method for Character Wrapper Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "valueOf() method for Character Wrapper Class" Watch "valueOf() method for Character Wrapper Class" New topic

valueOf() method for Character Wrapper Class

Tanya Shetty
Ranch Hand

Joined: Jun 17, 2009
Posts: 40

I am referring the SCJP 6 book by Kathy and Bert Bates...

Was referring table 3-3, Chapter 3, Page 243 for Wrapper Classes...

The valueOf() method in all numeric wrapper classes use a "string" or opt "string, radix" as an argument

For Boolean classes, valueOf() takes only "string" as a valid there is no radix for boolean

For Character classes however, valueOf() takes primitve type as an argument...

i.e. Character c = Character.valueOf('c');

Just did not find a mention of it in the text or the table 3-3.. came across it while on eclipse.. so thought of putting it down here..

If there is already an existing post of it.. sorry abt re-posting!

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 808

I remember that there is a mistake. Please, have a closer look at Boolean class.

Tanya Shetty
Ranch Hand

Joined: Jun 17, 2009
Posts: 40
Yes, had a look at the Errata and found the Boolean class bug related to the parseBoolean("String") method which is missing in table 3-3

However, coming back to the earlier discussion...

In the Boolean class... there exist 2 static valueOf() method,,
valueOf(boolean type arg ) and valueOf(String arg)

In fact,, for all numeric wrapper classes there exists 3 types of valueOf() methods, ie Byte, Short, Integer,Long,Float,Double

valueOf(respective primitive type arg)
valueOf(String arg)
valueOf(String arg, int radix)

Only for Character, there is a single type of method valueOf(character type primitve arg)...

Also, this is not really a mistake in the book as it does indeed state...

The two (well, usually two) static valueOf() methods provided in most of the wrapper classes give you another approach to creating wrapper classes.

It's only that one could miss it if we dont dig into the Wrapper class method further.. and only rely on table 3-3
Nitish Bangera
Ranch Hand

Joined: Jul 15, 2009
Posts: 537

Go through the api for the wrappers. This thing will be clear.

[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
Tanya Shetty
Ranch Hand

Joined: Jun 17, 2009
Posts: 40
Yea.. got the above info after reading the API for a few wrapper classes only ... Its definitely helpful
I agree. Here's the link:
subject: valueOf() method for Character Wrapper Class
jQuery in Action, 3rd edition