我的代码长这样:
List<String> filterList(List<String> list, String regex) {
List<String> result = new ArrayList<String>();
for (String entry : list) {
if (entry.matches(regex)) {
result.add(entry);
}
}
return result;
}
它返回一个仅包含与 regex
匹配的条目的列表。
我在想是否有内置函数可以做到这一点,类似于:
List<String> filterList(List<String> list, String regex) {
List<String> result = new ArrayList<String>();
result.addAll(list, regex);
return result;
}
List<String>
,但要考虑其他类型。 - Wundwin Born