Link Details

Link 1040187 thumbnail
User 1176525 avatar

By pengyifan
Published: Sep 29 2013 / 06:49

In general, Map is a data structure consisting of a set of key-value pairs, and each key can only appears once in the map. This post summarizes Top 9 FAQ of how to use Java Map and its implemented classes.
  • 13
  • 2
  • 1981
  • 2278
User 465559 avatar

Oussama SOUABNI replied ago:

0 votes Vote down Vote up Reply

Hashtable doesn't allow null value or null key. Please see the javadoc of put method : This class implements a hashtable, which maps keys to values. Any non-null object can be used as a key or as a value. Or even try it by your self, all the instructions bellow will throw a NullPointerException : hashTable.put(null, ""); hashTable.put("", null); hashTable.put(null, null); The first line in the implementation of function put: // Make sure the value is not null if (value == null) { // line 393 in Hashtable class throw new NullPointerException(); } and line 399 : int hash = key.hashCode(); throws NullPointerException when the key is null.

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java