Case Insensitive filtering using Google Guava -
current using following piece of code create filter, in map match , give filtered list of resultset.
final map filteredmap = maps.filterkeys(mymap, predicates.containspattern("^xyz"));
however guava predicates.containspattern case-sensitive matching.
how should use containspattern doing case-insensitive matching.
use
predicates.contains(pattern.compile("^xyz", pattern.case_insensitive))
as predicate instead. see core java pattern
, predicates.contains
.
edit (after op's comment): yes, can write:
predicates.containspattern("(?i)^xyz"))
(see pattern's documentation: case-insensitive matching can enabled via embedded flag expression (?i).) it's imo less self-explaining, plus compiled pattern
first example can cached private static final constant when used in loop, can improve performance.
Comments
Post a Comment