• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Collection doubt from Dan's mock test

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'.
 
Suman Nagelia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far my understanding of TreeMap it'll not accept any null key.
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try the following code. It compiles and runs. So I guess TreeMap does accept a null key and null values.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic