Collections.sort()和Arrays.sort()都是安装Comparable接口给的顺序关系从小到大排列数组。有什么办法让它从大到小排吗?比如某个方法里面有个boolean的参数,true是从小到大,false是从大到小。当然有个办法是在Comparable里把顺序关系反一下。但是那样看起来太奇怪了,明明语义上是它大,比较的时候非要说它小。
hu437:
Java API中说:
The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n log(n) performance. This implementation dumps the specified list into an array, sorts the array, and iterates over the list resetting each element from the corresponding position in the array.
除非要排序的目标数组有一定的特殊性,否则不可能写出比n log(n)更快的算法来,所以没有什么“自己写排序方法,效率最高”一说。都是人写的代码,凭什么自己写的就比SUN的人写的效率高呢?当然,如果目标数组有特殊性(比如基本已经按照一个顺序排好了,只要做一些调整就行了),自然自己写会好。我遇到的情况没有什么特殊性。
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。
本回答被网友采纳