Set的最大特點是能去掉重復的元素並獲取相應數據下面看個簡單的代碼先使用QBC查詢出所有員工在過濾掉重復的員工所在部門最後得到所有員工的部門串
view plain List<Employee> list = employeeDAOfindByExample(employee)Set set = new HashSet()for (int i = i < listsize() i++) { setadd(listget(i)getDepartmentId())} String deptIds = Iterator it = erator()while (ithasNext()) { deptIds = + itnext()toString() + }