list_set转化
来源:互联网 发布:python 日期和时间 编辑:程序博客网 时间:2024/05/16 18:43
1. 把 set转化成 有序的 List集合
public List<Tbpremission> findPremissionByUser(Integer userId) {
//根据主键找到用户Tbuser u = userDao.findById(Tbuser.class, userId);
//根据用户找到角色
Set<Tbrole> roles = u.getTbroles();
Set<Tbpremission> setp = new HashSet<Tbpremission>();
//根据角色获取权限
for(Tbrole r :roles){
setp.addAll(r.getTbpremissions());
}
//转List
List<Tbpremission> listp = new ArrayList<>(setp);
//排序
Collections.sort(listp,new Comparator<Tbpremission>() {
public int compare(Tbpremission o1, Tbpremission o2) {
if(o1.getPreId()>o2.getPreId())
return 1;
if(o1.getPreId()<o2.getPreId())
return -1;
return 0;
}
});return listp;
}
2. 把 LIst 中的 重复项去掉:
public List<Papers> getTestPaper() {
List<Papers> p=null;
String sql="select pap_id from papers_student_map where pap_id not in(select pap_id from papers_exercise_map) ";
List<String> ps=exerciseDao.findBySql(sql);
Set<String> pss=new HashSet<String>();
pss.addAll(ps); 直接把 List 转化为 Set ,去掉重复项
if(ps!=null&&ps.size()>0){
p=new ArrayList<Papers>();
List<Papers> p=null;
String sql="select pap_id from papers_student_map where pap_id not in(select pap_id from papers_exercise_map) ";
List<String> ps=exerciseDao.findBySql(sql);
Set<String> pss=new HashSet<String>();
pss.addAll(ps); 直接把 List 转化为 Set ,去掉重复项
if(ps!=null&&ps.size()>0){
p=new ArrayList<Papers>();
for(String psm : ps){
p.add(postTextbooksMapService.getPaperBypapId(psm));
}
}
//去重
Set<Papers> sp=new HashSet<Papers>();
sp.addAll(p);
p.clear();
p.addAll(sp);
for ( int i = 0 ; i < p.size() - 1 ; i ++ ) {
for ( int j = p.size() - 1 ; j > i; j -- ) {
if (p.get(j).equals(p.get(i))) {
p.remove(j);
}
}
}
return p;
}
0 0
- list_set转化
- 转化
- 强制转化
- 数制转化
- 类型转化
- 人民币转化
- ArrayList 转化
- 时间转化
- 坐标转化
- 日期转化
- 大小写转化
- 字符串转化
- 日期转化
- 转化问题
- 转化屏幕
- 矩阵转化
- 数据类型转化
- 字符串转化
- 解决android 应用首次启动的时候,闪现短暂的白屏或黑屏等
- React/React Native 的ES5 ES6写法对照表
- Android Priority Job Queue (Job Manager):线程任务的容错重启机制(二)
- PHP的魔术方法简介
- 【转载】Eclipse菜单栏详解
- list_set转化
- 【论文笔记】Joint Cascade Face Detection and Alignment
- 使用navigator.userAgent.toLowerCase()判断浏览器的类型
- PHP的MVC规范
- Python——PIP安装新的支持库
- node.js改网站图标小笔记
- 从原理上搞定编码-- Base64编码
- 【高级DP】目录
- 广播启动Activity