写一段Java代码,a数组是查询出来的对象,b数组也是查询出来的对象,a数组的值在b数组里面进行模糊匹配,并过滤掉匹配出来的值,将数组剩下的值返回出来
时间: 2023-06-04 13:04:18 浏览: 104
以下是Java代码:
public static List<Object> filterArray(Object[] a, Object[] b) {
List<Object> resultList = new ArrayList<>();
Set<Object> filterSet = new HashSet<>(Arrays.asList(b));
for (Object obj : a) {
boolean match = false;
for (Object filterObj : filterSet) {
if (filterObj.toString().contains(obj.toString())) {
match = true;
break;
}
}
if (!match) {
resultList.add(obj);
}
}
return resultList;
}
调用示例:
Object[] a = { "apple", "banana", "pear", "orange", "grape" };
Object[] b = { "apple juice", "banana bread", "watermelon", "grapefruit" };
List<Object> resultList = filterArray(a, b);
System.out.println(resultList); // 输出 [pear, orange]
阅读全文
相关推荐


















