Although the doubt is very basic, I would like to understand why equals
in this case:
String texto = null;
System.out.println("teste".equals(texto));
Return false
normally (example in ideone ), but in the example below:
String texto = null;
System.out.println(texto.equals(""));
It pops up the NullPointerException
exception, as can also be seen in the ideone .
In both cases there is a comparison with null
, but the return is different depending on which side null
is passed, why does this occur?