• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

valueOf() and parseXxx() for Character and Boolean wrapper classes - sounds like erratum in K&B

 
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to K&B (Page No. 243 table) :

1) valueOf() method takes the 'first argument' as only String representation and doesn't work for Character wrapper class.

2) parseXxx() method doesn't work for Boolean wrapper class

But, according to my tests :

1) valueOf() method is working for Character wrapper class with an argument taken in character representation i.e for instance, Character.valueOf('a')

2) parseXxx() method is working for Boolean wrapper class i.e for instance, Boolean.parseBoolean("True")

Please comment on this ......... what is your Opinion on these ?
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you check it with API?
 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While executing practice programs , i came to know that . Did you ever experience the same? Just for confirmation , i posted this topic and i did not check API till now.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should do that. Because, there may be some errors/versions in the K & B's book,
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prashanth,

just re-reading page 241, I don't see that it says that 'valueOf' only takes a String argument. Looking at the API it takes several depending on the wrapper. For instance, Integer has 3 versions of valueOf:

static Integer valueOf(int i)
static Integer valueOf(String s)
static Integer valueOf(String s, int radix)

Looking at the Character API, there is:

static Character valueOf(char c)

Perhaps the exam (and therefore the book) is only interested in the valueOf method that takes a String.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please note that the table on p. 243 is presented as "Common Wrapper Conversion Methods" only, not as an exhaustive list of all conversion methods. The authors are trying to focus our attention on what is important for the exam.
 
Prashanth Patha
Ranch Hand
Posts: 62
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all who replied to my topic.
 
Nothing? Or something? Like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic