【发布时间】:2011-11-26 09:46:29
【问题描述】:
我想按长度排序字符串的 ArrayList,但不只是按数字顺序。
例如,列表中包含以下单词:
cucumber
aeronomical
bacon
tea
telescopic
fantasmagorical
它们需要按长度不同排序为一个特殊的字符串,例如:
intelligent
所以最终列表看起来像这样(括号中的差异):
aeronomical (0)
telescopic (1)
fantasmagorical (3) - give priority to positive differences? doesn't really matter
cucumber (3)
bacon (6)
tea (8)
【问题讨论】:
-
如仅链接答案中所述,这可以使用Collections.sort() 来完成,它需要一个明确的Comparator