Java Utililty Methods Object Compare

List of utility methods to do Object Compare

Description

The list of methods to do Object Compare are organized into topic(s).

Method

booleanareEqual(final Object first, final Object second)
are Equal
return first.equals(second);
booleanareEqual(final Object o1, final Object o2)
Determines equality of the supplied objects by delegating to their hashCode methods.
if (o1 == null) {
    return o2 == null;
return o2 != null && (o1 == o2 || o1.getClass() == o2.getClass() && o1.hashCode() == o2.hashCode());
booleanareEqual(final Object object0, final Object object1)
Whether two objects are equal, without throwing a null pointer exception.
if ((object0 == null) && (object1 == null)) {
    return true;
if ((object0 == null) || (object1 == null)) {
    return false;
return object0.equals(object1);
booleanareEqual(final Object x, final Object y)
Returns true if the given objects are equal, namely, they are both null or they are equal by the equals() method.
return x == null ? y == null : x.equals(y);
booleanareEqual(final T object1, final T object2)
Null safe comparison of instances, especially numerics like Integer.
if (object1 == object2) {
    return true;
if (object1 == null || object2 == null) {
    return false;
if (object1.equals(object2)) {
    return true;
...
booleanareEqual(Object aThis, Object aThat)
Equals for possibly-null object field.
if (isArray(aThis) || isArray(aThat)) {
    throw new IllegalArgumentException("This method does not currently support arrays.");
return aThis == null ? aThat == null : aThis.equals(aThat);
booleanareEqual(Object first, Object second)
Compares two objects.
if (first == second) {
    return true;
} else {
    if (first != null && second != null) {
        return first.equals(second);
    return false;
booleanareEqual(Object first, Object second, boolean equalEvenIfBothNull)
are Equal
return (equalEvenIfBothNull ? areEqualEvenIfBothNull(first, second) : areEqual(first, second));
booleanareEqual(Object o1, Object o2)
are Equal
return o1 == null ? o2 == null : o1.equals(o2);
booleanareEqual(Object o1, Object o2)
are Equal
return !(o1 == null || o2 == null || !o1.equals(o2));