使用自定义比较器:
public class MyComparator implements java.util.Comparator<String> { private int referenceLength; public MyComparator(String reference) { super(); this.referenceLength = reference.length(); } public int compare(String s1, String s2) { int dist1 = Math.abs(s1.length() - referenceLength); int dist2 = Math.abs(s2.length() - referenceLength); return dist1 - dist2; }}然后使用对列表进行排序
java.util.Collections.sort(List, Comparator)。



