I research a position of my key in hashMap.
Example :
HashMap<Integer, String> ht = new HashMap(); ht.put(1, "c"); ht.put(10, "b"); ht.put(8, "r"); System.out.println(ht);
10 has position 3 in HashMap, 8 has position 2 …
So I have two questions :
- how to retreive these positions from HashMap?
- When i have a much element, i use hashMap to retreive a positions or Binary Search ?
HashMapis not a sorted or orderedMapimplementation, so there isn’t a “position” here.LinkedHashMapis an ordered one,TreeMapis a sorted one.