当前位置:   article > 正文

对List中的对象的模糊查询_list 模糊查询 c++

list 模糊查询 c++

将string和 controlPersonList中的Id和Name作比较。

Matcher类的matches()方法是全字段匹配,find()方法是模糊搜搜匹配

  1. @Override
  2. public void doSearch(String string, List<ControlPerson> controlPersonList, List<ControlCar> controlCarsList) {
  3. List<ControlPerson> personSearchResult = new ArrayList<>();
  4. List<ControlCar> carSearchResult = new ArrayList<>();
  5. Pattern pattern = Pattern.compile(string);
  6. for(int i = 0; i<controlPersonList.size(); i++){
  7. Matcher matcher1 = pattern.matcher(controlPersonList.get(i).getId());
  8. Matcher matcher2 = pattern.matcher(controlPersonList.get(i).getName());
  9. if(matcher1.matches() || matcher2.matches()){
  10. personSearchResult.add(controlPersonList.get(i));
  11. }
  12. }
  13. for(int i = 0; i<controlCarsList.size(); i++){
  14. Matcher matcher3 = pattern.matcher(controlCarsList.get(i).getPlate());
  15. if(matcher3.matches()){
  16. carSearchResult.add(controlCarsList.get(i));
  17. }
  18. }
  19. iFilterControlDataView.initPersonList(personSearchResult);
  20. iFilterControlDataView.initCarList(carSearchResult);
  21. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/1022320
推荐阅读
相关标签
  

闽ICP备14008679号