Skip to content
Advertisement

Tag: lexicographic-ordering

What is the equivalent way to do Ordering.lexicographical() in Java 8 Comparator?

Is there a way to implement Ordering.lexicographical() with Java 8 Comparator? Comparator.thenCompare seems to be limited in this Answer Seemingly not, no. As a result, Guava still provides this functionality, but in the new class Comparators: https://guava.dev/releases/snapshot/api/docs/com/google/common/collect/Comparators.html#lexicographical(java.util.Comparator). Note that Guava generally does a good job telling you whether and how to migrate off of it to new Java features, so

String Comparison in Java

What does “compare two strings lexicographically” mean? Answer Leading from answers from @Bozho and @aioobe, lexicographic comparisons are similar to the ordering that one might find in a dictionary. The Java String class provides the .compareTo () method in order to lexicographically compare Strings. It is used like this “apple”.compareTo (“banana”). The return of this method is an int which

Advertisement