Skip to main content
added 161 characters in body
Source Link
Colin Hebert
  • 93.5k
  • 15
  • 164
  • 154

You won't gain anything by checking that the key exists. This is the code of HashMap:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

Just check if the return value for get() is different from null.

This is the HashMap source code.


Resources :

You won't gain anything by checking that the key exists. This is the code of HashMap:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

Just check if the return value for get() is different from null.

This is the HashMap source code.


Resources :

You won't gain anything by checking that the key exists. This is the code of HashMap:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

Just check if the return value for get() is different from null.

This is the HashMap source code.


Resources :

added 54 characters in body; added 18 characters in body; added 63 characters in body
Source Link
Colin Hebert
  • 93.5k
  • 15
  • 164
  • 154

You won't gain anything by checking that the key exists. This is the code of HashMap:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

Just check if the return value for get() is different from null.

This is the HashMap source code.


Resources :

You won't gain anything:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

This is the HashMap source code.


Resources :

You won't gain anything by checking that the key exists. This is the code of HashMap:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

Just check if the return value for get() is different from null.

This is the HashMap source code.


Resources :

Post Undeleted by Colin Hebert
Post Deleted by Colin Hebert
Source Link
Colin Hebert
  • 93.5k
  • 15
  • 164
  • 154

You won't gain anything:

@Override public boolean containsKey(Object key) { Entry<K, V> m = getEntry(key); return m != null; } @Override public V get(Object key) { Entry<K, V> m = getEntry(key); if (m != null) { return m.value; } return null; } 

This is the HashMap source code.


Resources :