Search for a regexp in a java arraylist

前端 未结 6 1766
失恋的感觉
失恋的感觉 2020-12-14 19:13
ArrayList  list = new ArrayList(); 
list.add(\"behold\");
list.add(\"bend\");
list.add(\"bet\");
list.add(\"bear\");
list.add(\"beat\");
list.add(\"bec         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 19:50

    One option is to use Apache Commons CollectionUtils "select" method. You would need to create a Predicate object (an object with a single "evaluate" method that uses the regular expression to check for a match and return true or false) and then you can search for items in the list that match. However, it won't return the indexes, it will return a collection containing the items themselves.

提交回复
热议问题