Java - Filtering List Entries by Regex

前端 未结 3 1747
孤街浪徒
孤街浪徒 2020-12-29 07:42

My code looks like this:

List filterList(List list, String regex) {
  List result = new ArrayList();
         


        
3条回答
  •  执笔经年
    2020-12-29 08:16

    In java 8 you can do something like this using new stream API:

    List filterList(List list, String regex) {
        return list.stream().filter(s -> s.matches(regex)).collect(Collectors.toList());
    }
    

提交回复
热议问题