Forums Register Login

Doubt with String Methods

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Do you have K & B for (java-5) book? If you have read page-230 & 231 care fully. You will clear.
+Pie Number of slices to send: Send
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);
+Pie Number of slices to send: Send
Thanks Tony Smith for explaining .
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 751 times.
Similar Threads
How do OBJECTS pass messages in Java?
Lucene - get TermVector positions
Inheritance of all members
servlet security
What is the logic behind calls like JOptionPane.method()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:13:13.