集合进行查询数据

2020-03-12  本文已影响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;
    }
上一篇下一篇

猜你喜欢

热点阅读