title: Java Key-Value Collection with complexity of O(1) for millions of random unordered keys
body: <p>I am stuck with a problem where I have millions of key-value pairs that I need to access using the keys randomly (not by using an iterator). </p>
  
  <p>The range of keys is not known at compile time, but total number of the key-value pairs is known.</p>
  
  <p>I have looked into <strong>HashMap</strong> and <strong>Hashset</strong> data structures but they are not truly <strong>O(1)</strong> as in case of collision in the hash-code they become array of <strong>LinkedLists</strong> which has linear search complexity at worst case.</p>
  
  <p>I have also considered increasing the number of <strong>buckets</strong> in the <strong>HashMap</strong> but it does not ensure that every element will be stored in a separate bucket.</p>
  
  <p>Is there any way to store and access millions of key-value pairs with <strong>O(1)</strong> complexity?</p>
  
  <p>Ideally I would like every key to be like a variable and corresponding value should be the value assigned to that key </p>
  
  <p>Thanks in advance. </p>