写一段Java代码,a数组是查询出来的对象,b数组也是查询出来的对象,a数组的值在b数组里面进行模糊匹配,并过滤掉匹配出来的值,将数组剩下的值返回出来
时间: 2023-06-04 11:04:18 浏览: 102
以下是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]
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)