| Author |
Wrapper classes?
|
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
The statements below, Boolean b1 = Boolean.valueOf("True"); Boolean b2 = Boolean.valueOf("True"); System.out.println(b1 == b2); //prints true Double d1 = Double.valueOf("10"); Double d2 = Double.valueOf("10"); System.out.println(d1 == d2);//prints false Any reasons??
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Aniket Patil
Ranch Hand
Joined: May 02, 2006
Posts: 218
|
|
You have already asked this question here: http://www.coderanch.com/t/260776/java-programmer-SCJP/certification/Boolean-Wrappers Also see http://www.coderanch.com/t/260471/java-programmer-SCJP/certification/Wrapper [ December 21, 2006: Message edited by: Aniket Patil ]
|
SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
|
 |
hemadri raju
Greenhorn
Joined: Mar 28, 2006
Posts: 15
|
|
In order to save memory, two instances of the following wrapper objects will always be == when their primitive values are the same: Boolean Byte Character from \u0000 to \u007f (7f is 127 in decimal) Short and Integer from -128 to 127 hope that will help.
|
 |
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
|
|
And what about this? Long l = -128L; Long m = -128L; System.out.println(l==m); Yours, Bu
|
all events occur in real time
|
 |
ramya ray
Ranch Hand
Joined: Aug 11, 2006
Posts: 101
|
|
is This applicable for 1.4 , as in my case below code is giving false... Integer i = Integer.valueOf("1"); Integer j = Integer.valueOf("1"); System.out.println(i==j);
|
 |
Kalpesh Jain
Ranch Hand
Joined: May 29, 2006
Posts: 30
|
|
And what about this? Long l = -128L; Long m = -128L; System.out.println(l==m);
its clearly written at SCJP FAQs on javaranch Note: The Java Language Specification does not explicitly guarantee this behavior for long values within the range of a byte. [ December 21, 2006: Message edited by: Kalpesh Jain ]
|
Its a j a v a
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
[hemadri raju]: In order to save memory, two instances of the following wrapper objects will always be == when their primitive values are the same: Always?
|
"I'm not back." - Bill Harding, Twister
|
 |
Maneeesh Saxena
Greenhorn
Joined: Dec 24, 2006
Posts: 26
|
|
hi all, can you please mention the source from where to study above all. is it part of SCJP1.4??? I've read K&B (SCJP1.4) but this is not covered there so please tell me the source for the same. Regards
|
 |
Prabhu Venkatachalam
Ranch Hand
Joined: Nov 16, 2005
Posts: 502
|
|
For SCJP 1.4 exam, whatever there in K&B book is fine. If you want learn about wrapper classes. Lot of links available in SCJP FAQ
|
Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
|
 |
 |
|
|
subject: Wrapper classes?
|
|
|