【发布时间】:2012-11-21 07:36:50
【问题描述】:
我有一系列需要按规则排序的对象。但是我需要能够切换规则,但是我有一组有限的排序规则。哪种数据结构是最好的选择?
作为一个例子,我有这个类:
class Test {
public final int amount;
public final int cost;
public final String name;
public final int whatever;
// ...
// TODO: add a constructor to set the fields :-)
}
我如何存储这些字段以按金额、成本、名称或其他方式对其进行排序。但只是其中一条规则。
我可以想象使用ArrayList 或HashSet,我使用自定义Comparator 调用排序函数。但我无法想象这就是效率。我认为这在移动设备上很重要。有什么更好的方法来实现这一目标?
【问题讨论】:
标签: java android performance list