版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/sunknew/article/details/78834646
中文中讲集合有序,就是指集合是ordered,ordered是数据结构层面的有序。sorted是基于ordered的,指可根据排序规则(通常基于数据值)对数据进行排序。
- ordered,其顺序是基于数据结构的,与其中所存对象的值没有关系,比如,ArrayList是基于索引的,LinkedHashSet是基于插入顺序的。
- sorted,其顺序是相应类通过实现Comparable或Comparator接口达到的,一般是基于对象属性值的,比如,String,Integer实现了Comparable接口,分别照字母顺序和数字大小这种自然顺序排列。
- not ordered,比如,HashTable,虽然其也有一套基于hashcode的内部逻辑来决定顺序,但是这个逻辑对使用者是不可见的,因而是无序的。
集合框架常见具体实现类的ordered与sorted属性
参考:
1.What is the difference between an ordered and a sorted collection?
2.Collections/Generics