This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes null values of collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "null values of collections" Watch "null values of collections" New topic
Author

null values of collections

natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Can anyone say how many null values are allowed in the following collections:
(1) ArrayList
(2) TreeMap
(3) LinkedList
(4) HashSet
(5) HashMap
I know hashtable does not allow any null values. The API does not clearly say this. It just says ArrayList, etc. allow values including null.
TIA.

Sun Certified Programmer for Java 2 Platform
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
(1) ArrayList
(2) TreeMap
(3) LinkedList
(4) HashSet
(5) HashMap
All of them allow null values. Try it. The only thing is in a set values must be unique. SO if you add another null the value will not be added or it will be removed and a new null value be added i don't remember.


Val SCJP <BR>going for SCJD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null values of collections
 
Similar Threads
Collections questions
100% in SCJP 5.0
HashSet question
Why does HashMap allow 'null' values
Difference between arraylist.clear(); arralist=null