File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
Mahesh Bansal
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the collection classes can contain null items and under what conditions.
Can someone please explain.
Thanks
Mahesh
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
thanks,
Natarajan
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic