Java Utililty Methods Object Equal

List of utility methods to do Object Equal

Description

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

Method

booleanequals(Object o1, Object o2)
Test two objects for equality safely.
return (o1 == o2) || ((o1 != null) && o1.equals(o2));
booleanequals(Object o1, Object o2)
equals
if (o1 == null) {
    return o2 == null;
if (o2 != null && o1.getClass().isArray() && o2.getClass().isArray()) {
    try {
        return Arrays.deepEquals((Object[]) o1, (Object[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((boolean[]) o1, (boolean[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((byte[]) o1, (byte[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((char[]) o1, (char[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((double[]) o1, (double[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((float[]) o1, (float[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((int[]) o1, (int[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((long[]) o1, (long[]) o2);
    } catch (ClassCastException ignore) {
    try {
        return Arrays.equals((short[]) o1, (short[]) o2);
    } catch (ClassCastException ignore) {
return o1.equals(o2);
booleanequals(Object o1, Object o2)
Tests if specified objects are equal using equals().
return ((o1 == null && o2 == null) || (o1 != null && o1.equals(o2)));
booleanequals(Object object1, Object object2)
equals
boolean result;
if (object1 == object2) {
    result = true;
} else if (object1 == null) {
    result = false;
} else if (object1 instanceof boolean[] && object2 instanceof boolean[]) {
    result = Arrays.equals((boolean[]) object1, (boolean[]) object2);
} else if (object1 instanceof int[] && object2 instanceof int[]) {
...
booleanequals(Object thisObj, Object thatObj)
Compares two objects.
if (thisObj == null) {
    return thatObj == null;
} else if (thatObj == null) {
    return false;
final Class<?> clazz = thisObj.getClass();
if (!clazz.equals(thatObj.getClass())) {
    return false;
...
booleanequals(Object v1, Object v2)
equals
boolean rval = true;
if (v1 instanceof List && v2 instanceof List) {
    if (((List) v1).size() != ((List) v2).size()) {
        rval = false;
    } else {
        for (int i = 0; i < ((List<Object>) v1).size() && rval == true; i++) {
            rval = equals(((List<Object>) v1).get(i), ((List<Object>) v2).get(i));
} else if (v1 instanceof Number && v2 instanceof Number) {
    double n1 = ((Number) v1).doubleValue();
    double n2 = ((Number) v2).doubleValue();
    rval = n1 == n2;
} else if (v1 instanceof String && v2 instanceof String) {
    rval = ((String) v1).equals((String) v2);
} else if (v1 instanceof Map && v2 instanceof Map) {
    if (((Map) v1).size() != ((Map) v2).size()) {
        rval = false;
    } else {
        for (Object k1 : ((Map) v1).keySet()) {
            rval = ((Map) v2).containsKey(k1) ? equals(((Map) v1).get(k1), ((Map) v2).get(k1)) : false;
            if (rval != true) {
                break;
} else if (v1 instanceof Boolean && v2 instanceof Boolean) {
    rval = v1 == v2;
} else if (v1 != null && v2 != null) {
    rval = v1.equals(v2);
} else {
    rval = v1 == v2;
return rval;
booleanequals(Object x, Object y)
equals
return x == y || (x != null && y != null && x.equals(y));
booleanequals(Object... objects)
Equals for a series of objects
if (objects.length < 2) {
    return true;
for (int i = 1; i < objects.length; i++) {
    if (!equal(objects[0], objects[i])) {
        return false;
return true;
booleaninternalEquals(Object[] o1, Object[] o2)
internal Equals
for (int i1 = 0; i1 < o1.length; i1++) {
    final Object obj1 = o1[i1];
    boolean matchFound = false;
    for (int i2 = 0; !matchFound && i2 < o1.length; i2++) {
        final Object obj2 = o2[i2];
        if (obj1.equals(obj2)) {
            matchFound = true;
            o2[i2] = null;
...
booleanisEquals(final Object lhs, final Object rhs)
is Equals
if (!lhs.getClass().isArray()) {
    return lhs.equals(rhs);
} else if (lhs instanceof int[]) {
    return Arrays.equals((int[]) lhs, (int[]) rhs);
} else if (lhs instanceof long[]) {
    return Arrays.equals((long[]) lhs, (long[]) rhs);
} else if (lhs instanceof byte[]) {
    return Arrays.equals((byte[]) lhs, (byte[]) rhs);
...