Java Object Compare areEqual(Object object1, Object object2)

Here you can find the source of areEqual(Object object1, Object object2)

Description

Returns true if the two objects are either both null, or equal.

License

Apache License

Parameter

Parameter Description
object1 The first object to test for equality with the second object.
object2 The second object to test for equality with the first object.

Return

True if the two objects are either both null, or equal.

Declaration

public static boolean areEqual(Object object1, Object object2) 

Method Source Code

//package com.java2s;
/*//w w  w.  jav a2 s  .com
 Copyright 2008 Jenkov Development

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

public class Main {
    /**
     * Returns true if the two objects are either both null, or equal. If the
     * objects are both non-null equality is determined by the call
     * <code>object1.equals(object2)</code>.
     * @param object1 The first object to test for equality with the second object.
     * @param object2 The second object to test for equality with the first object.
     * @return True if the two objects are either both null, or equal.
     */
    public static boolean areEqual(Object object1, Object object2) {
        if (object1 != null && object2 != null)
            return (object1.equals(object2));
        else if (object1 == null && object2 != null)
            return false;
        else if (object1 != null && object2 == null)
            return false;
        return true;
    }
}

Related

  1. areEqual(Object o1, Object o2)
  2. areEqual(Object obj, Object obj2)
  3. areEqual(Object obj1, Object obj2)
  4. areEqual(Object obj1, Object obj2)
  5. areEqual(Object obj1, Object obj2)
  6. areEqual(Object one, Object another)
  7. areEqual(Object parameter, Object otherParameter)
  8. areEqual(Object value, Object otherValue)
  9. areEqual(Object value1, Object value2)