Java String Equal areStringsEqual(String one, String two)

Here you can find the source of areStringsEqual(String one, String two)

Description

Checks if two strings are equal - handles nulls

License

Open Source License

Parameter

Parameter Description
one a parameter
two a parameter

Declaration

public static boolean areStringsEqual(String one, String two) 

Method Source Code

//package com.java2s;
/**/* w  ww.j  av  a 2 s .c o m*/
 * Project: JLIB
 * Version: $Id$ 
 * License: (see below block, or the accompanied COPYING.txt file)
 **************************************************************************************** LICENSE BEGIN *****
 * Copyright (c) 2009-2013, JLIB AUTHORS (see the AUTHORS.txt file for the list of the individuals)
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided 
 * that the following conditions are met:
 * 
 *  1) Redistributions of source code must retain the above copyright notice, this list of conditions and the 
 *     following disclaimer.
 *  2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and 
 *     the following disclaimer in the documentation and/or other materials provided with the distribution.
 *  3) Neither the names of the organisations involved in the JLIB project, nor the names of their 
 *     contributors to the JLIB project may be used to endorse or promote products derived from this software 
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************************** LICENSE END *****
 * 
 * This file is best viewed with 110 columns.
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
 * 
 * In chronological order
 * Author(s):
 *   Dejan Lekic , http://dejan.lekic.org
 * Contributor(s):
 *   -
 */

public class Main {
    /**
     * Checks if two strings are equal - handles nulls
     * @param one
     * @param two
     * @return 
     */
    public static boolean areStringsEqual(String one, String two) {
        boolean nullDiff = one == null ^ two == null;
        boolean valueDiff = one != null && two != null && !one.equals(two);

        return !nullDiff && !valueDiff;
    }
}

Related

  1. areEquals(final String s1, final String s2)
  2. areEqualsIgnoreCaseAndTrim(final String s1, final String s2)
  3. areEqualXMLValues(String s1, String s2)
  4. areStringEquals(String s1, String s2)
  5. areStringEquals(String string1, String string2)
  6. areStringsEqual(String s1, String s2, boolean caseInsensitive)
  7. areStringsEqual(String s1, String s2, boolean caseInsensitive, boolean dontDistinctNullAndEmpty)
  8. areStringsEqual(String str1, String str2)
  9. collapseQualifier(String qualifier, boolean includeDots)