Java Object Equal areEqual(Object o1, Object o2)

Here you can find the source of areEqual(Object o1, Object o2)

Description

Determines is two objects are equal, accounting for one or both objects being null or the two objects being array types.

License

Open Source License

Parameter

Parameter Description
o1 The first object to compare.
o2 The second object to compare.

Return

True if the two objects are equal.

Declaration

public static final boolean areEqual(Object o1, Object o2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * /*  www .j  a va 2  s. co  m*/
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/

import java.util.Arrays;

public class Main {
    /******************************************************************************
     * Determines is two objects are equal, accounting for one or both
     * objects being null or the two objects being array types.
     * @param o1  The first object to compare.
     * @param o2  The second object to compare.
     * @return  True if the two objects are equal.
     ******************************************************************************/
    public static final boolean areEqual(Object o1, Object o2) {
        boolean objectsAreEqual = false;
        if (o1 == o2) {
            objectsAreEqual = true;
        } else if (o1 != null && o2 != null) {
            if (o1.getClass().isArray() && o2.getClass().isArray()) {
                objectsAreEqual = Arrays.equals((Object[]) o1, (Object[]) o2);
            } else {
                objectsAreEqual = o1.equals(o2);
            }
        }

        return objectsAreEqual;
    }
}

Related

  1. areEqual(final Object x, final Object y)
  2. areEqual(Object o1, Object o2)
  3. areEqualStr(Object o1, Object o2)
  4. deepEquals(Object o1, Object o2)
  5. equalObjects(Object object1, Object object2)