List集合排序

来源:互联网 发布:北大青鸟的网络课程 编辑:程序博客网 时间:2024/06/15 23:33
HttpSession session = request.getSession();List<Order> orderList=(List)session.getAttribute("exportList");Collections.sort(orderList, new Comparator<Order>() {    /*     * int compare(Order o1, Order o2) 返回一个基本类型的整型,     * 返回负数表示:o1 小于o2,     * 返回0 表示:o1和o2相等,     * 返回正数表示:o1大于o2。     */    public int compare(Order o1, Order o2) {        //按照学生的年龄进行升序排列        if (Integer.parseInt(o1.getOrderNo()) > Integer.parseInt(o2.getOrderNo())) {            return 1;        }        if (Integer.parseInt(o1.getOrderNo()) == Integer.parseInt(o2.getOrderNo())) {            return 0;        }        return -1;    }});
原创粉丝点击