Java - 按正则表达式过滤列表条目
2022-09-02 14:13:35
						我的代码如下所示:
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;
}