Java Object Compare areEqual(Object o1, Object o2)

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

Description

Checks whether two objects are equal.

License

Open Source License

Declaration

public static boolean areEqual(Object o1, Object o2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w w w.j av  a2s  .c o m*/
     * Checks whether two objects are equal.  This is null-safe and considers null and empty string to be equal
     */
    public static boolean areEqual(Object o1, Object o2) {
        Object obj1 = nvl(o1, "");
        Object obj2 = nvl(o2, "");
        return obj1.equals(obj2);
    }

    /**
     * Returns the passed object, if not null, or replacement otherwise
     */
    public static <T extends Object> T nvl(T o, T replacement) {
        return (isNull(o) ? replacement : o);
    }

    /**
     * Returns true if object is null or empty String
     */
    public static boolean isNull(Object o) {
        return o == null || o.equals("");
    }
}

Related

  1. areEqual(Object first, Object second, boolean equalEvenIfBothNull)
  2. areEqual(Object o1, Object o2)
  3. areEqual(Object o1, Object o2)
  4. areEqual(Object o1, Object o2)
  5. areEqual(Object o1, Object o2)
  6. areEqual(Object obj, Object obj2)
  7. areEqual(Object obj1, Object obj2)
  8. areEqual(Object obj1, Object obj2)
  9. areEqual(Object obj1, Object obj2)