相关疑难解决方法(0)

Java - 由Regex过滤列表条目

我的代码看起来像这样:

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)

java regex collections

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

collections ×1

java ×1

regex ×1