Android Utililty Methods String Compare

List of utility methods to do String Compare

Description

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

Method

intcompare(String s1, String s2)
Comare two string
return s1 == null ? (s2 == null ? 0 : -1) : s1.compareTo(s2);
intcompare(String lhs, String rhs)
compare
if (lhs == null) {
    return rhs == null ? 0 : 1;
return rhs == null ? -1 : lhs.compareTo(rhs);
booleancompare(String str1, String str2)
compare
return (str1 == null || str2 == null) ? str1 == str2 : str1
        .equals(str2);
intcompareToIgnoreCase(String s1, String s2, boolean nullsAreGreater)
Compares two strings, guarding against nulls.
if (s1 == s2) {
    return 0; 
if (s1 == null) {
    return nullsAreGreater ? 1 : -1;
if (s2 == null) {
    return nullsAreGreater ? -1 : 1;
...
intcompareToIgnoreCase(String s1, String s2, boolean nullsAreGreater)
Compares two strings, guarding against nulls.
if (s1 == s2) {
    return 0; 
if (s1 == null) {
    return nullsAreGreater ? 1 : -1;
if (s2 == null) {
    return nullsAreGreater ? -1 : 1;
...
intcompare(String s1, String s2)
compare
if (isNullOrEmpty(s1) && isNullOrEmpty(s2)) {
    return 0;
} else if (isNullOrEmpty(s1)) {
    return 1;
} else if (isNullOrEmpty(s2)) {
    return -1;
return s1.compareToIgnoreCase(s2);
...