java - HashMap<String, Integer> Search for part of an key? -
this question has answer here:
- partial search in hashmap 4 answers
i using hashmap<string, integer> filled keys of type string all, let's say, 5 chars long. how can search specific key of 4 chars or less, part , @ beginning of other keys , hits collection of <key, value>?
iterate option unless create custom data structure:
for (entry<string, integer> e : map.entryset()) { if (e.getkey().startswith("xxxx")) { //add result list } } if need more time efficient you'd need implementation of map tracking these partial keys.
Comments
Post a Comment