Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

We need a little bit of background for this. In Java the == operator checks if two variables are pointing to the same object. The .equals() method checks for actual value equality.

  new String("Hi")==new String("Hi"); // False
  new String("Hi").equals(new String("Hi")); // True
Except for primitives like ints and floats where == does value comparison.

  1==1;// True
For NaN the value comparison is false. Even then .equals returns true

  Float.NaN==Float.NaN; // False
  new Float(0f/0f).equals(new Float(0f/0f)); // True!!!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: