Java中对List进行字典序排序
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
private List<Type> list = new ArrayList<>();
Collections.sort(list, new Comparator<Type>() {
@Override
public int compare(Type o1, Type o2) {
return o1.compareTo(o2);
}
});
//倒序排列
Collections.reverse(list);
网友评论