排序方法对任何对象进行排序 [英] Sorting Method for sort any object

查看:95
本文介绍了排序方法对任何对象进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分选方法在Java其中使用排序任何对象传递作为参数并返回排序对象

解决方案
不能排序的任何对象。

严格来说,您可以只按排序订单标准定义

如果您需要对集合进行排序(例如,一个对象的数组,然后后者必须提供一个属性(比如''key''),这样使用它你就能确定任何 2的相对顺序它们。

假设对象提供了这样的,那么你可以使用一个众所周知的好算法(例如快速排序 [ ^ ])用于排序。


Sorting Method in java which use to sort any Object pass as parameter and return sorted Object

解决方案

You cannot ''sort any object''.
Strictly speaking you may just sort sets having an order criterion defined.
If you need sorting a collection (e.g. an array) of objects then the latter must provide a property (say ''key'') such that using it you are be able establish the relative order of any two of them.
Supposing the objects provide such a key then you may use a well-known-good algorithm (like for instance Quick Sort[^] ) for sorting them.


这篇关于排序方法对任何对象进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆