Posts

Showing posts from December, 2017

Java – HashMap in-detail explanation

Image
HashMap works based on hashing algorithm, As per Java doc HashMap has below four constructors, Constructor Description HashMap ​() Constructs an empty HashMap  with the default initial capacity (16) and the default load factor (0.75). HashMap ​(int initialCapacity) Constructs an empty HashMap  with the specified initial capacity and the default load factor (0.75). HashMap ​(int initialCapacity, float loadFactor) Constructs an empty HashMap  with the specified initial capacity and load factor. HashMap ​( Map <? extends  K ,? extends  V > m) Constructs a new HashMap  with the same mappings as the specified Map . Let’s write simple java program, to examine how Map works internally Create a simple Map and add one key and value to it 1 public   static   void   main(String[] args) { 2   3 Map<Integer, String> map =  new   HashMap<>(); 4   ...