我的代码看起来像这样:
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;
}
Run Code Online (Sandbox Code Playgroud)
它返回一个列表,其中只包含与之匹配的条目regex
.我想知道是否有这样的内置功能:
List<String> filterList(List<String> list, String regex) {
List<String> result = new ArrayList<String>();
result.addAll(list, regex);
return result;
}
Run Code Online (Sandbox Code Playgroud)