Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valueOf() method for Character Wrapper Class

 
Tanya Shetty
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

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 argument..as 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
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember that there is a mistake. Please, have a closer look at Boolean class.
 
Tanya Shetty
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through the api for the wrappers. This thing will be clear.
 
Tanya Shetty
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea.. got the above info after reading the API for a few wrapper classes only ... Its definitely helpful
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic