I have big code and such lines:
System.out.println(car.getName());
System.out.println(car.getName() == null);
First line print outs:
null
but second line print outs false, so null == null is false?
I have also tried System.out.println(car.getName() == "null"); since getName returns String but same result
When it comes to String you need to use the
equalsmethod:if it actually returns the String “null” which is not the same as
null.Why using
equalsinstead of==, I can’t find a simpler explanation than this one: