Java Object Equal objectsEqual(Object lhs, Object rhs)

Here you can find the source of objectsEqual(Object lhs, Object rhs)

Description

Compare two objects in a null-safe manner.

License

Open Source License

Parameter

Parameter Description
lhs The first object to compare.
rhs The second object to compare.

Return

true is both objects are null or lhs.equals(rhs), otherwise false.

Declaration

public static boolean objectsEqual(Object lhs, Object rhs) 

Method Source Code

//package com.java2s;
/*************************************************************************************
 * Copyright (c) 2011, 2012, 2013 James Talbut.
 *  jim-emitters@spudsoft.co.uk//  w  w w .  j av a 2  s  .c  o m
 *  
 * 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
 * 
 * Contributors:
 *     James Talbut - Initial implementation.
 ************************************************************************************/

public class Main {
    /**
     * Compare two objects in a null-safe manner.
     * @param lhs
     * The first object to compare.
     * @param rhs
     * The second object to compare.
     * @return
     * true is both objects are null or lhs.equals(rhs), otherwise false.
     */
    public static boolean objectsEqual(Object lhs, Object rhs) {
        return (lhs == null) ? (rhs == null) : lhs.equals(rhs);
    }
}

Related

  1. isEquals(Object object1, Object object2)
  2. nullSafeEquals(Object o1, Object o2)
  3. nullSafeEquals(Object o1, Object o2)
  4. objectsEqual(final Object objectA, final Object objectB)
  5. objectsEqual(Object a, Object b)
  6. objectsEqual(Object o1, Object o2)
  7. objectsEqual(Object o1, Object o2)
  8. objectsEqual(Object obj1, Object obj2)
  9. objectsEqual(T a, T b)