The behavior of a sorted set is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Set interface.
有用吗?
这实际上为您想要实现特定行为提供了灵 active 。例如,假设您想将字符串放入 SortedSet 中并忽略大小写对它们进行排序,您可以使用:
Set<String> set = new TreeSet<> (String.CASE_INSENSITIVE_ORDER);