Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with String Methods

 
anmita payal
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand the clear difference between xxxValue(),ParseXxx() and valueOf() methods. Any one can explain me these with simple example?
Thanks
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have K & B for (java-5) book? If you have read page-230 & 231 care fully. You will clear.
 
Tony Smith
Ranch Hand
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use the first one xxxValue() method you need to have an object created already. For example:

Integer i = new Integer(15);
System.out.println(i.intValue());
System.out.println(i.byteValue());
System.out.println(i.doubleValue());

it will print out the int, byte, double primitive values of the Integer object i.


The following two: parseXxx() and valueOf() are static methods. So that means you can call them by using Integer.parseXxx() or Integer.valueOf().

And the difference betweent the two is that parseXxx() returns primitive but valueOf()returns object. They generally takes String as input. For example:

int a = Integer.parseInt("15");
System.out.println(a);

Integer b = Integer.valueOf("15");
System.out.println(b);
 
anmita payal
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony Smith for explaining .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic