File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Collections" Watch "Collections" New topic


Mahesh Bansal
Ranch Hand

Joined: Nov 28, 2000
Posts: 82
Which of the collection classes can contain null items and under what conditions.
Can someone please explain.
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
All collection collections can have null items. Including sets (but only one allowed). This means others can have more than one.
Maps can have one key as null, and multiple values as null.
I am little bit doubtful. Can anyone confirm me please?

Sun Certified Programmer for Java 2 Platform
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Set can have no dups and at most 1 null.
List can have dups and many nulls.
Maps can have no dup keys (but can have dup elements) and SOME maps allow nulls
HashMap allows nulls
TreeMap allow nulls EXCEPT those that use natural ordering.
HashTable does NOT allow nulls.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Don't get me started about those stupid light bulbs.
subject: Collections
It's not a secret anymore!