All
I have read these links,
Is there a way to get the value of a HashMap randomly in Java?
Selecting random key and value sets from a Map in Java
using toArray()
on keySet and list.get()
is not an option. Because these methods take O(n) time.
All the methods described in the above links take O(n) worst case to get a random value from hash map
. Is it possible to do this in O(1) time?.