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(Object value, Object otherValue)
A comprehensive isEqual method that handles nulls and arrays safely.
if (value == otherValue) {
    return true;
if (value == null) {
    return false;
if (otherValue == null) {
    return false;
...
booleanareEqual(Object value1, Object value2)
Compares the two given values by taking null and NaN values into account.
Two null values will be considered equal.
return ((value1 == null) && (value2 == null)) || (isNaN(value1) && isNaN(value2))
        || ((value1 != null) && value1.equals(value2));
booleanareEqual(T obj1, T obj2)
are Equal
return (obj1 != null) && obj1.equals(obj2);
voidareEqual(T obj1, V obj2)
are Equal
areEqual(obj1, obj2, "The object is not equal.");
booleanareEqualComparables(T object1, T object2)
are Equal Comparables
if (object1 == null) {
    return (object2 == null);
} else if (object2 == null) {
    return false;
return (object1.compareTo(object2) == 0);
booleanareEqualEvenIfBothNull(Object first, Object second)
are Equal Even If Both Null
return ((first == null && second == null) || (first != null && second != null && first.equals(second)));
booleanareEquals(final Object o1, final Object o2)
Utility method for equals() methods.
return (o1 == o2) || (o1 != null && o1.equals(o2));
booleanareEquals(Object a, Object b)
are Equals
if (a == null) {
    return b == null;
return a.equals(b);
booleanareEquals(Object arg0, Object arg1)
Checks if the given objects are equals using the Object#equals(Object) method or the == operator if the first argument is null.
if (arg0 != null && arg1 != null) {
    return arg0.equals(arg1);
return arg0 == arg1;
booleanareEquals(Object... objs)
are Equals
boolean areEquals = true;
if (objs != null && objs.length > 1) {
    for (int i = 0; i < objs.length - 1 && areEquals; i++) {
        areEquals &= (objs[i] == null && objs[i + 1] == null)
                || (objs[i] != null && objs[i].equals(objs[i + 1]));
return areEquals;
...