This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collection doubt from Dan's mock test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Collection doubt from Dan Watch "Collection doubt from Dan New topic
Author

Collection doubt from Dan's mock test

Suman Nagelia
Greenhorn

Joined: Mar 17, 2003
Posts: 9
Hi
I have one problem with the following question answer:

a. Stores key/value pairs.
b. Allows null elements, keys, and values.
c. Duplicate entries replace old entries.
d. Entries are sorted using a comparator or the
Comparable interface.

Which of these classes provides the specified features?
a. LinkedList
b. TreeMap
c. TreeSet
d. HashMap
e. HashSet
f. Hashtable
g. None of the above

Answer is TreeMap
But according to my understanding answer should be g. None of the above as TreeMap doesn't satisfies the second condition "b. Allows null elements, keys, and values." Treemap allows null values but doesn't allow null key .
Can anyone give more thought on this and explain to me is anywhere I am wrong in understanding the question or what?
Thanks
Karthik Veeramani
Ranch Hand

Joined: Dec 22, 2002
Posts: 132
Correct me if im wrong, but cant a TreeMap take 1 null key (and many null values)... I guess the question means only this, by 'accepting null'.


Thanks<br />Karthik<br />SCJP 1.4, CCNA.<br /> <br />"Success is relative. More the success, more the relatives."
Suman Nagelia
Greenhorn

Joined: Mar 17, 2003
Posts: 9
As far my understanding of TreeMap it'll not accept any null key.
Rory French
Ranch Hand

Joined: Apr 03, 2003
Posts: 97
try the following code. It compiles and runs. So I guess TreeMap does accept a null key and null values.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collection doubt from Dan's mock test
 
Similar Threads
Collections from Dan's Exam
Dan's mock exam: collection classes
Dan's ? from Collections.
Map null values doubt
danchisholm.net HashMap Question