You can use
str1.compareTo(str2);
If str1 is lexicographically less than str2, a negative number will be returned, 0 if it is equal, or a positive number if str1 is greater.
For example,
"a".compareTo("b"); // returns a negative number, here -1 "a".compareTo("a"); // returns 0 "b".compareTo("a"); // returns a positive number, here 1 "b".compareTo(null); // throws java.lang.NullPointerException
Johan SjΓΆberg Mar 01 2018-11-11T00: 00Z
source share