实体类集合(List<Object>)根据实体类的一个或者多个属性对集合进行排序-Collections.sort

来源:互联网 发布:生日视频制作软件 编辑:程序博客网 时间:2024/06/13 09:00
Collection.sort(userList, new Comparator<user>(){@Overridepublic int compare(User u1, User u2){int ct=0;if(u2 == null){ct = -1;}if(ct == 0){String userId = u1.getUserId();String o_userId = u2.getUserId();if(userId == null){userId = "";}if(o_userId == null){o_userId = "";}ct = userId.compareTo(o_userId);if(ct == 0){String id = u1.getId();String o_id = u2.getId();if( id == null){id = "";}if(o_id == null){o_id = "";}ct = id.compareTo(o_id);}}return ct;}});

阅读全文
0 0
原创粉丝点击