1 问题
对list里面的对象名字进行模糊查询
2 解决办法
//即可以进行模糊匹配
matcher.find()
//匹配查询
matcher.matches()
/**
* 模糊查询
*/
public static ArrayList search(String name, List list) {
ArrayList results = new ArrayList();
Pattern pattern = Pattern.compile(name);
// 如果要求大小写不敏感,改成:
// Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE);
for (int i = 0; i < list.size(); i++) {
Matcher matcher = pattern.matcher(((SearchBean)list.get(i)).getName());
//匹配查询
//matcher.matches()
if (matcher.find()) {
results.add(list.get(i));
}
}
return results;
}