• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic