Link to home
Start Free TrialLog in
Avatar of komputer
komputer

asked on

hashmap find by like

hi,

i would like to use searh in hashmap (or similar with it) with like operator ('%') like in sql.
how can i do?

imagine i have a map like that;
1000, a1
1001, a2
2000, b1
2001, b2

what i need it when i run like this map.get(10%), it will give an array of object that contains a1, a2

thanks in advance.


 
Avatar of schybert
schybert

The only way I can think of of the top of my head is to implement your own Map class. Possibliy just extending HashMap. You then need to override the get method so that it searches the key set for keys that match your wildcard pattern. Let me know if you want details...
Avatar of komputer

ASKER

i need a solution, an open-source lib or source code.
ASKER CERTIFIED SOLUTION
Avatar of schybert
schybert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooops, the cast to sKey is unnecessary of course.

Usage is:

List l = CollectionUtil.wildcardGet("10\\w*", myMap);
What kind of objects are a1, a2
alhough it not what i look for (since it iterates all object and this will cause performance problems), i will accept, cause i have not found a geniric solution.

thanks guys.