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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -