| Author |
scenerio from examLab
|
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1047
|
|
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
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
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!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Rene Argento
Greenhorn
Joined: Jun 09, 2010
Posts: 10
|
|
|
Hmm Priority Queue seems to fit the scenario, as it allows duplicate items and sort them implicitly.
|
SCJA | SCJP6 | OCE SQL | OCA DBA 10g
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
Exactly, PriorityQueue is the answer!
|
 |
 |
|
|
subject: scenerio from examLab
|
|
|