• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections questions

 
Vidya Venkatesh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi I have some doubts in Collections.
Are there any collections which do not allow null values ?
Can objects of any class be used as the key of a HashMap ?
 
Chetan M
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vidya ,
As for as ur second question is concerned ,
For HashMap infact for any collection, objects can't be used as the key.
 
Lakshmi Dasari
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vidya,
Hashtable does not allow null value. HashMap can contain a 'null' key and null values. Set can contain atmost one null value.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lakshmi,
Welcome to Javaranch, a friendly place for Java greenhorns.
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with the JavaRanch Naming Policy.
Thanks Pardner!
Hope to see you 'round the Ranch!
[ March 07, 2003: Message edited by: Dan Chisholm ]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, Chetan M, your name is also not in line with the naming policy.

Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy
Oh Yeah -
List allows duplicates and nulls
Vector allows duplicates and null (sort of - at the end)
Set allows NO duplicates and up to 1 null
But there is no guarantee that someone could not create a Collection that prohibits nulls.
[ March 07, 2003: Message edited by: Cindy Glass ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic