package container.main;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet; import container.bean.GxyJobEntity; public class RemoveSame {
public static void main(String[] args) {
List<GxyJobEntity> list = new ArrayList<>();
GxyJobEntity gxyJobEntity1 = new GxyJobEntity();
gxyJobEntity1.setUserId("user001");
gxyJobEntity1.setPlanId("plan001");
gxyJobEntity1.setStudentId("stu001"); GxyJobEntity gxyJobEntity2 = new GxyJobEntity();
gxyJobEntity2.setUserId("user002");
gxyJobEntity2.setPlanId("plan002");
gxyJobEntity2.setStudentId("stu002"); GxyJobEntity gxyJobEntity3 = new GxyJobEntity();
gxyJobEntity3.setUserId("user003");
gxyJobEntity3.setPlanId("plan001");
gxyJobEntity3.setStudentId("stu001"); list.add(gxyJobEntity1); list.add(gxyJobEntity2); list.add(gxyJobEntity3); List<GxyJobEntity> list1 = removeDuplicate(list);
System.out.println(list);
System.out.println(list1);
} private static List<GxyJobEntity> removeDuplicate(List<GxyJobEntity> list) {
Set<GxyJobEntity> set = new TreeSet<GxyJobEntity>(new Comparator<GxyJobEntity>() {
public int compare(GxyJobEntity a, GxyJobEntity b) {
System.out.println("a:" + a);
System.out.println("b:" + b); // 字符串则按照asicc码升序排列
if ( a.getStudentId().equals(b.getStudentId()) &&
a.getPlanId().equals(b.getPlanId()) ) {
return 0;
} else {
return 1;
}
}
});
System.out.println("set:" + set.size() + "-->" + set);
set.addAll(list);
System.out.println("set:" + set.size() + "-->" + set);
return new ArrayList<GxyJobEntity>(set);
} }  

如果 对象 GxyJobEntity 中两个属性  studentId 和 planId 相等,则保留一个,去掉多余的。

输出:

set:0-->[]
a:GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001]
b:GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001]
a:GxyJobEntity [jobId=null, studentId=stu002, planId=plan002, userId=user002]
b:GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001]
a:GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user003]
b:GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001]
set:2-->[GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001], GxyJobEntity [jobId=null, studentId=stu002, planId=plan002, userId=user002]]
[GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001], GxyJobEntity [jobId=null, studentId=stu002, planId=plan002, userId=user002], GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user003]]
[GxyJobEntity [jobId=null, studentId=stu001, planId=plan001, userId=user001], GxyJobEntity [jobId=null, studentId=stu002, planId=plan002, userId=user002]]

根据规则去掉List 对象数组中的重复元素的更多相关文章

  1. 去掉有序数组中的重复元素 c/c++

    去掉有序数组中的重复元素: int RemoveDuplates(int A[], int nCnt) { ; ; , j = ; i < nCnt && j < nCnt ...

  2. Java-Runoob-高级教程-实例-数组:10. Java 实例 – 查找数组中的重复元素-un

    ylbtech-Java-Runoob-高级教程-实例-数组:10. Java 实例 – 查找数组中的重复元素 1.返回顶部 1. Java 实例 - 查找数组中的重复元素  Java 实例 以下实例 ...

  3. 【leetcode-82,83,26,80】 删除排序链表/数组中的重复元素

    83. 删除排序链表中的重复元素 (1 pass) 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: ...

  4. LeetCode#26 | Remove Duplicates from Sorted Array 删除有序数组中的重复元素

    一.题目 Description Given a sorted array, remove the duplicates in-place such that each element appear ...

  5. 获取JS数组中所有重复元素

    //获取数组内所有重复元素,并以数组返回 //例:入参数组['1','2','4','7','1','2','2'] 返回数组:['1','2'] function GetRepeatFwxmmc(a ...

  6. 26. Remove Duplicates from Sorted Array(删除排序数组中的重复元素,利用排序的特性,比较大小)

      Given a sorted array, remove the duplicates in-place such that each element appear only once and r ...

  7. 计蒜客--移除数组中的重复元素 (set)

    给定一个升序排列的数组,去掉重复的数,并输出新的数组的长度. 例如:数组 A = \{1, 1, 2\}A={1,1,2},你的程序应该输出 22 即新数组的长度,新数组为 \{1, 2\}{1,2} ...

  8. JSK 11: 移除数组中的重复元素

    题目描述 给定一个升序排列的数组,去掉重复的数,并输出新的数组的长度. 例如:数组 $A = \{1, 1, 2\}$,你的程序应该输出 $2$ 即新数组的长度,新数组为 $\{1, 2\}$. 要求 ...

  9. 74 使用BitSet输出数组中的重复元素

    [本文链接] http://www.cnblogs.com/hellogiser/p/using-bitset-to-print-duplicate-elements-of-array.html [题 ...

随机推荐

  1. jsp下拉列表

    <c:set var="REPORT_TYPE_NORMAL" value="<%=SysIndexFormTemp.REPORT_TYPE_NORMAL%& ...

  2. Thinkphp3.2.3关于开启DEBUG正常,关闭DEBUG就报错模版无法找到,页面错误!请稍后再试~

    这是Thinkphp3.2.3的一个坑- 具体原因也没搞清楚,测试环境都是好的,线上就出问题,是因为线上debug是关闭的 具体原委特此记录: 现象:(打开DEBUG就正常了,所以界面看不到具体报错滴 ...

  3. Rasterize order group

    增加shade 这里的并行 可以让更多 ...并行只在write那里wait 语法 struct I {float a [[raster_order_group(0)]];};

  4. Educational Codeforces Round 22 B. The Golden Age(暴力)

    题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...

  5. Codeforces Round #586 (Div. 1 + Div. 2) C. Substring Game in the Lesson

    链接: https://codeforces.com/contest/1220/problem/C 题意: Mike and Ann are sitting in the classroom. The ...

  6. CodeForces 837D - Round Subset | Educational Codeforces Round 26

    /* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...

  7. axios请求提交的form data格式 明明是JSON格式的参数却转成了字符串格式

    问题:传的参数成为了字符数格式 解决:把参数的格式转换 const params = new URLSearchParams() params.append('USER_LOGIN', 'admin' ...

  8. BZOJ 2982 combination 脑子+组合数学

    可以发现,整个数列构成一个树形结构,并且是个完全二叉堆(小根堆). 并且这个堆的形态在给定$n$后是固定的,第1个位置上显然只能放1. 对子树的根来说,他自己是所分得的数集中最小的那个,所以从剩下$s ...

  9. HDU - 6150 构造题

    最近的vj好垃圾,老崩,实名吐槽 HDU - 6150 题意:给出一个错误的求最小点覆盖的函数,需要来构造一组样例,使得那个函数跑出来的答案是正解的3倍以上. 很巧妙的构造技巧,首先想法就是弄一个二分 ...

  10. 灰度变换,gama变换,对数,反对数变换

    学习DIP第2天 灰度变换,及按照一定规则对像素点的灰度值进行变换,变换的结果可以增强对比度,或者达到其他的效果(例如二值化,或者伽马变换),由于灰度变换为针对单个像素点的灰度值进行变换,素以算法复杂 ...