Float f1=new Float(Float.NAN), f2=new Float(Float.NAN) Why is f1.equals(f2) true and why is Float.NAN==Float.NAN false? Dosn't equals(of Float) look at the value of f1 which is Float.NAN and isn't it equivalent to doing f1==f2?
The Float.equals method compares the bit patterns of the primitive float value. By comparing the bit patterns the unusual behavior of NaN is avoided. The javadoc for the Float.equals method covers this issue in detail. The source code for Float.equals is as follows.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Joined: Nov 16, 2000
This clears it up. I assume it's the same for all other Number wrapper classes.