使用此方法Collections.sort(List,Comparator)。实施比较器并将其传递给
Collections.sort().
class RecipeCompare implements Comparator<Recipe> { @Override public int compare(Recipe o1, Recipe o2) { // write comparison logic here like below , it's just a sample return o1.getID().compareTo(o2.getID()); }}
然后使用
Comparatoras
Collections.sort(recipes,new RecipeCompare());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)