This commit is contained in:
Victor Shcherb 2018-07-11 01:14:54 +02:00
parent 19abc90f38
commit f00a89e0e8

View file

@ -674,4 +674,21 @@ public class Algorithms {
return (x < y) ? -1 : ((x == y) ? 0 : 1); return (x < y) ? -1 : ((x == y) ? 0 : 1);
} }
public static int compare(final String str1, final String str2) {
return compare(str1, str2, false);
}
public static int compare(final String str1, final String str2, final boolean nullIsLess) {
if (str1 == str2) {
return 0;
}
if (str1 == null) {
return nullIsLess ? -1 : 1;
}
if (str2 == null) {
return nullIsLess ? 1 : - 1;
}
return str1.compareTo(str2);
}
} }