I need a Map but when I call get(key, n) it should should return not only all the records with the searched key value, but also all where the n last significant bits of the key are the same as the search key (e.g. applying something like key&(1<<(n+1)-1)).
Is there something like this already implemented in Java?
Not quite, but you can use a NavigableMap.subMap to implement this. e.g.
If you want to search based on the lowest bits instead of the highest bits, you have to reverse the bits before adding and searching. This will group together the lowest bit, second lowest bit then third lowest bit etc.