集合进行查询数据

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;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容