java的List集合去除重复的对象

方法之一:List集合转化成Set集合,
去重后,如果还需要List类型的参数,在把set对象转回成List对象就好了

//有重复数据的list对象
List<ImgEntryResponse> mImgHistoryList = new ArrayList();
//set去重,set集合添加List数据
 Set<ImgEntryResponse> mSetHistoryList = new HashSet<ImgEntryResponse>();
 mSetHistoryList.addAll(mImgHistoryList);
 //Set转化成List
 List<ImgEntryResponse> mListOnly = new ArrayList<>(mSetHistoryList);
 //如果需要排序的话使用LinkedHashSet...唯一而且有序

有问题私信作者me…

猜你喜欢

转载自blog.csdn.net/ShiXinXin_Harbour/article/details/111646298