HashMap<String, Integer> Search for part of an key? [duplicate]
问题 This question already has answers here : Partial search in HashMap (5 answers) Closed 3 years ago . I am currently using HashMap<String, Integer> which is filled with keys of type String which are all, let's say, 5 chars long. How can I search for an specific key of 4 chars or less, which is part and at the beginning of some other keys and get all hits as a collection of <Key, Value> ? 回答1: Iterate is your only option unless you create a custom data structure: for (Entry<String, Integer> e :