You can use Objects.equals()
from java.util.Objects
if(Objects.equals(value1, value1){
//your code
}
In documentation it said, this will check null and value as well.
Implementation from Java doc:
Returns true if the arguments are equal to each other and false otherwise.
Consequently, if both arguments are null, true is returned and if exactly one
argument is null, false is returned. Otherwise, equality is determined by using
the equals method of the first argument.
Params: a – an object
b – an object to be compared with a for equality
Returns: true if the arguments are equal to each other and false otherwise
See Also: Object.equals(Object)
public static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
}