• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

scenerio from examLab

 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly, PriorityQueue is the answer!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic