Java Utililty Methods String Equal

List of utility methods to do String Equal

Description

The list of methods to do String Equal are organized into topic(s).

Method

booleanareEqualIgnoreCase(String s1, String s2)
are Equal Ignore Case
if (s1 == null && s2 == null)
    return true;
if (s1 != null) {
    s1 = s1.toLowerCase();
    return s2 != null && s1.equals(s2.toLowerCase());
} else {
    return false;
booleanareEqualIgnoreNull(String value1, String value2, boolean caseSensitive)
Compares the given values and returns true if they are equal.
if (value1 == null || value1.equals("")) {
    return true;
} else {
    if (caseSensitive && value1.equals(value2)) {
        return true;
    } else if (!caseSensitive && value1.equalsIgnoreCase(value2)) {
        return true;
    } else {
...
booleanareEqualLexemes(String l1, String l2)
Sometimes different API methods deliver different results, e.g.
if (l1.equals(l2)) {
    return true;
String l1_relaxed = l1.replaceAll(" ", "_");
String l2_relaxed = l2.replaceAll(" ", "_");
if (l1_relaxed.equals(l2_relaxed)) {
    return true;
return false;
booleanareEquals(final String origin, final String checkWith)
are Equals
return !isNullOrEmpty(origin) && origin.equals(checkWith);
booleanareEquals(final String s1, final String s2)
Compare two String to see if they are equals (both null is ok).
return s1 == null ? s2 == null : s1.equals(s2);
booleanareEqualsIgnoreCaseAndTrim(final String s1, final String s2)
Compare two String to see if they are equals ignoring the case and the blank spaces (both null is ok).
if (s1 == null && s2 == null) {
    return true;
} else if (s1 != null && s2 != null) {
    return s1.trim().equalsIgnoreCase(s2.trim());
} else {
    return false;
booleanareEqualXMLValues(String s1, String s2)
Test if two strings are equal in XML.
return ((s1 == null && s2 == null) || (s1 == null && isEmpty(s2)) || (isEmpty(s1) && s2 == null)
        || (s1 != null && s1.equals(s2)));
booleanareStringEquals(String s1, String s2)
Indicates if two Strings are equals, managing null.
if (s1 == null) {
    return s2 == null;
return s1.equals(s2);
booleanareStringEquals(String string1, String string2)
Checks if two strings are equals.
if (string1 == null && string2 == null) {
    return false;
} else if (string1 != null && !string1.equals(string2)) {
    return false;
} else if (string2 != null && !string2.equals(string1)) {
    return false;
return true;
...
booleanareStringsEqual(String one, String two)
Checks if two strings are equal - handles nulls
boolean nullDiff = one == null ^ two == null;
boolean valueDiff = one != null && two != null && !one.equals(two);
return !nullDiff && !valueDiff;