Java Object Compare areEqual(Object obj1, Object obj2)

Here you can find the source of areEqual(Object obj1, Object obj2)

Description

Tests whether two object references refer to equal objects.

License

Apache License

Parameter

Parameter Description
obj1 object reference
obj2 object reference

Return

true if both references are null, OR if neither is null and both objects are equal; false otherwise

Declaration

public static boolean areEqual(Object obj1, Object obj2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  w  w.  j a  va 2 s.c om*/
     * Tests whether two object references refer to equal objects. The object
     * references can both be null, in which case they are also considered equal.
     * @param obj1 object reference
     * @param obj2 object reference
     * @return true if both references are null, OR if neither is null and both
     * objects are equal; false otherwise
     */
    public static boolean areEqual(Object obj1, Object obj2) {
        if (obj1 == obj2) {
            return true;
        } else if (obj1 == null || obj2 == null) {
            return false;
        } else {
            return obj1.equals(obj2);
        }
    }
}

Related

  1. areEqual(Object o1, Object o2)
  2. areEqual(Object o1, Object o2)
  3. areEqual(Object o1, Object o2)
  4. areEqual(Object o1, Object o2)
  5. areEqual(Object obj, Object obj2)
  6. areEqual(Object obj1, Object obj2)
  7. areEqual(Object obj1, Object obj2)
  8. areEqual(Object object1, Object object2)
  9. areEqual(Object one, Object another)