List 通过 Collections.binarySearch 进行记录筛选

1.

Collections.sort(list, new Comparator<TreeDto>() {
    @Override
    public int compare(TreeDto a2, TreeDto b2) {
        return a2.getId().compareTo(b2.getId());
    }
});

Collections.binarySearch(list,new TreeDto(null,null,Integer.valueOf(paramId),null,null,null,null,null), new Comparator<TreeDto>() {
    @Override
    public int compare(TreeDto o1, TreeDto o2) {
        // TODO Auto-generated method stub
        if (o1.getPid() != null && o2.getPid() != null) {
            return o1.getPid().compareTo(o2.getPid());
        }else if (o1.getPid() == null && o2.getPid() == null) {
            return 0;
        }
        return -1;
    }
});

 

posted @ 2017-09-04 12:48  如.若  阅读(394)  评论(0编辑  收藏  举报