1

There is a String.CASE_INSENSITIVE_ORDER but why is there no String.CASE_SENSITIVE_ORDER? Or is there such an order somewhere hidden?

principal-ideal-domain
  • 3,998
  • 8
  • 36
  • 73

2 Answers2

5

Case-sensitive ordering is the default; i.e. String#compareTo is case-sensitive. Therefore, there is no explicit Comparator for it.

Collections.sort(myStringList);  // case sensitive ("natural ordering")

Collections.sort(myStringList, String.CASE_INSENSITIVE_ORDER);  // case insensitive
arshajii
  • 127,459
  • 24
  • 238
  • 287
  • Is this default comparator extractable? – principal-ideal-domain Dec 28 '15 at 22:37
  • 1
    @principal-ideal-domain In Java 8, yes, using [`Comparator.naturalOrder()`](https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html#naturalOrder--). Perhaps [this](http://stackoverflow.com/questions/3241063/does-a-natural-comparator-exist-in-the-standard-api) will be of interest to you as well. – arshajii Dec 28 '15 at 22:41
  • Most things default to the natural ordering without you having to specify it explicitly. – Louis Wasserman Dec 28 '15 at 23:24
3

Because String.CASE_SENSITIVE_ORDER is by default

v.ladynev
  • 19,275
  • 8
  • 46
  • 67