美文网首页
集合进行查询数据

集合进行查询数据

作者: 黑芝麻胡 | 来源:发表于2020-03-12 11:19 被阅读0次

    1、进行模糊查询 切忽略大小写 根据 name 查询 matcher.find() 模糊查询

      Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE); 忽略大小写
    
     public List<StaffListBean.InfoBean> search(String name,List<StaffListBean.InfoBean> list){
            List results = new ArrayList();
            Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE);
            for(int i=0; i < list.size(); i++){
                Matcher matcher = pattern.matcher(((StaffListBean.InfoBean)list.get(i)).getName());
                if(matcher.find()){
                    results.add(list.get(i));
                }
            }
            return results;
        }
    

    2、进行精确查询 根据 name 查询 修改方法 matcher.matches()

       public List<StaffListBean.InfoBean> search(String name,List<StaffListBean.InfoBean> list){
            List results = new ArrayList();
            for(int i=0; i < list.size(); i++){
                Matcher matcher = pattern.matcher(((StaffListBean.InfoBean)list.get(i)).getName());
                if(matcher.matches()){
                    results.add(list.get(i));
                }
            }
            return results;
        }

    相关文章

      网友评论

          本文标题:集合进行查询数据

          本文链接:https://www.haomeiwen.com/subject/epbyjhtx.html