Question: In .NET `System.Object` defines a static method

```
bool Equals(object a, object b);

```

That is a useful alternative to `a.Equals(b)` in cases where `a` may be `null`. It also returns true if both `a` and `b` are `null`.

I can't find an equivalent method in Java's framework (my Java is a bit rusty these days.) The most succinct code I can muster is:

```
(a==null && b==null) || (a!=null && a.Equals(b))

```

Does such a method exist?

**NOTE** I don't want to take a dependency on any external framework. I'm just curious if this simple method exists in the core Java class library.

Answer: 
I think what you want is [ObjectUtils.equals](http://commons.apache.org/lang/api-2.6/org/apache/commons/lang/ObjectUtils.html#equals%28java.lang.Object,%20java.lang.Object%29).

```
 ObjectUtils.equals(null, null)                  = true
 ObjectUtils.equals(null, "")                    = false
 ObjectUtils.equals("", null)                    = false
 ObjectUtils.equals("", "")                      = true
 ObjectUtils.equals(Boolean.TRUE, null)          = false
 ObjectUtils.equals(Boolean.TRUE, "true")        = false
 ObjectUtils.equals(Boolean.TRUE, Boolean.TRUE)  = true
 ObjectUtils.equals(Boolean.TRUE, Boolean.FALSE) = false

```

If you are interested, here is the code from the library...

```
public static boolean equals(Object object1, Object object2) {
    if (object1 == object2) {
        return true;
    }
    if ((object1 == null) || (object2 == null)) {
        return false;
    }
    return object1.equals(object2);
}

```
[ObjectUtils](http://commons.apache.org/lang/api-release/org/apache/commons/lang/ObjectUtils.html) in [Apache Common](http://commons.apache.org/)s provides such a [method](http://commons.apache.org/lang/api-release/org/apache/commons/lang/ObjectUtils.html#equals%28java.lang.Object,%20java.lang.Object%29).