您可以使用自定义比较器以您认为合适的任何方式对列表元素进行排序。
final List<Element<Integer, Integer>> list = new ArrayList<Element<Integer, Integer>>();
list.add(new Element<Integer, Integer>(1, 1));
list.add(new Element<Integer, Integer>(4, 4));
list.add(new Element<Integer, Integer>(3, 3));
list.add(new Element<Integer, Integer>(2, 2));
list.add(new Element<Integer, Integer>(5, 5));
Collections.sort(list, new Comparator<Element<Integer, Integer>>() {
@Override
public int compare(final Element<Integer, Integer> x,
final Element<Integer, Integer> y) {
return x.getPriority().compareTo(y.getPriority());
}
});
// Prints elements in ascending order of priority
System.out.println(Arrays.toString(list.toArray()));