Generic Compare two object, allowing nulls - Android java.util

Android examples for java.util:Collection and Null

Description

Generic Compare two object, allowing nulls

Demo Code

/*// w w w.j av a  2  s  . com
 *******************************************************************************
 * Copyright (C) 1996-2015, International Business Machines Corporation and    *
 * others. All Rights Reserved.                                                *
 *******************************************************************************
 */

public class Main{
    /**
     * Compare, allowing nulls
     * @param a
     * @param b
     * @return
     */
    public static <T> boolean equals(T a, T b) {
        return a == null ? b == null : b == null ? false : a.equals(b);
    }
}

Related Tutorials