1

While trying to declare the HashMap normally the code is written as

 Map<K,V> m = new HashMap<>();

If I try to create a hash map by the below mentioned code :

 HashMap<K,V> m = new HashMap<>();

What is the difference between the two declarations and which one should be preferred ?

Sarvagya Dubey
  • 435
  • 1
  • 7
  • 22
  • 2
    *"...and which one should be preferred ?"* The first, unless you need something `HashMap` provides that `Map` doesn't. See the linked question's answers for details. – T.J. Crowder May 02 '18 at 16:22

0 Answers0