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

booleanareStringsEqual(String s1, String s2, boolean caseInsensitive)
are Strings Equal
if (s1 == null)
    return s2 == null;
if (caseInsensitive)
    return s1.equalsIgnoreCase(s2);
else
    return s1.equals(s2);
booleanareStringsEqual(String s1, String s2, boolean caseInsensitive, boolean dontDistinctNullAndEmpty)
are Strings Equal
if (dontDistinctNullAndEmpty) {
    if (s1 == null || s1.length() == 0)
        return s2 == null || s2.length() == 0;
return areStringsEqual(s1, s2, caseInsensitive);
booleanareStringsEqual(String str1, String str2)
Return whether the 2 passed strings are equal.
if (str1 == null && str2 == null) {
    return true;
if (str1 != null) {
    return str1.equals(str2);
return str2.equals(str1);
StringcollapseQualifier(String qualifier, boolean includeDots)
Given a qualifier, collapse it.
StringTokenizer tokenizer = new StringTokenizer(qualifier, ".");
String collapsed = Character.toString(tokenizer.nextToken().charAt(0));
while (tokenizer.hasMoreTokens()) {
    if (includeDots) {
        collapsed += '.';
    collapsed += tokenizer.nextToken().charAt(0);
return collapsed;
booleanequalsCaseless(String sA_, String sB_)
Compares two strings.
String sFirst = sA_.toUpperCase();
String sSecond = sB_.toUpperCase();
return sFirst.equals(sSecond);
booleanequalsIgnoreCase(String s1, String s2)
equals Ignore Case
return (s1 != null ? s1.equalsIgnoreCase(s2) : s2 == null);
booleanequalsIgnoreCase(String source, String query)
equals Ignore Case
String parsedQuery = query.replace("f/", "").trim();
List<String> strings = Arrays.asList(source.toLowerCase());
return strings.stream().filter(s -> s.contains(parsedQuery.toLowerCase())).count() > 0;
booleanequalsOrExceeds(String version, String threshold)
Returns true if the given version is the same or more recent then the threshold version.
int versionIndex = knownVersions.indexOf(version);
int thresholdIndex = knownVersions.indexOf(threshold);
if (versionIndex == -1 || thresholdIndex == -1) {
    return false;
return versionIndex >= thresholdIndex;
floatgetEquality(String str1, String str2)
Analyze two strings to determine how much they differ.
String lineDelimiter = System.getProperty("line.separator");
StringTokenizer st1 = new StringTokenizer(str1, lineDelimiter);
StringTokenizer st2 = new StringTokenizer(str2, lineDelimiter);
int linecount1 = 0; 
int linecount2 = 0; 
int samecount = 0; 
int addedcount = 0; 
int deletedcount = 0; 
...
booleanisEqual(String str, String str2, boolean isCaseSensitive)
is Equal
return isNotEmpty(str) && isNotEmpty(str2) ? isCaseSensitive ? str.equals(str2) : str.equalsIgnoreCase(str2)
        : false;