Forums Register Login

scenerio from examLab

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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!
+Pie Number of slices to send: Send
Hmm Priority Queue seems to fit the scenario, as it allows duplicate items and sort them implicitly.
+Pie Number of slices to send: Send
Exactly, PriorityQueue is the answer!
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1022 times.
Similar Threads
order of elements returned by Iterator in Set
Collections
Vector , Map ,set
Difference between Comparable and Comparator interfaces
HashMaps
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:59:07.