Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scenerio from examLab

 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this question is from examlab practice exam 2

Ques; the progrmmer wants to create a telephone directory,and that should be ordered implicitly in terms of its name and it could allow duplicate names in it also.........what should be used
for that



As per my understanding what i see is (i am not sure please see my below explaination for both collection and map) according to that nothing get fixed into the above scenerio


lets go one by one.........
here it is

set----it doesnot allow duplicate values and ordered is unpredictable and unsorted also
hashset----doesnot allow duplicate value and order is unpredictable and unsorted also
linkedhashset-->doesnot allow duplicate value and order is similer to data is inserted and unsorted
Treeset---->doesnot allow duplicate values but it is sorted and ordered also.
arraylist--->allow duplicate values but doesnot sort it and its method are also not synchronized
vector---->allow duplicate values but doesnot sort it and it method are sychronized
Hashmap--->doesnot allow duplicate keys.......but it sort it in natural order......null key is not there in it....it method are also not synchronized..
Hashtable--->doesnot allow duplicate keys.......but it sort it in natural order......one null key is allowed....it method are also synchronized..
linkedhashmap-->doesnot allow duplicate keys.....order is same as it is inserted......
priority queue---->elements are sorted in their natural ordering......



none from the above gets fixed into above scenerio..........as the above scenerio requires both duplicate key and they are also implicitly sorted by their name,


Thanks in advance..........
and please correct me if i am wrong in the my above explaination of the map and collection
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
phil sohar wrote:
Hashmap--->doesnot allow duplicate keys.......but it sort it in natural order......null key is not there in it....it method are also not synchronized..
Hashtable--->doesnot allow duplicate keys.......but it sort it in natural order......one null key is allowed....it method are also synchronized..


HashMap allows one null key and multiple null values and it's no ordered and sorted.
Hashtable doesn't let you have any null in it, and it's not ordered and sorted!
 
Rene Argento
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm Priority Queue seems to fit the scenario, as it allows duplicate items and sort them implicitly.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly, PriorityQueue is the answer!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic