• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Picking the right Collection class Question.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm taking the LearnKey mock exam and there i found a question about collections that caught me. The question and its answer are bellow:

"A programmer needs his application to support a collection that will allow the fastest possible traversal of extended travel itineraries. In addition, the application must support the fastest possible traversal of all customers based on the order in which they applied for discount cards. Which class(es) best support these requirements? (Chosse one or two)
a) java.util.Vector
b) java.util.HashSet
c) java.util.TreeSet
d) java.util.HashList
e) java.util.ArrayList
f) java.util.LinkedList
g) java.util.LinkedHashSet"

The answer are letters:

e) and g)

What I did not understand was why LinkedHashSet was chosen too. It is not clear for me that a Set was needed when I read the question.

Can you provide some help on this?

thanks,

bruno
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea, I got this question wrong as well. I chose the LinkedList for the collection to store customers applying for discount cards.

I think you need a Set for the customers that apply for discount card because you don't want to record duplicate requests. You only want to know if a customer has applied for a discount card. The Set needs to be linked because you want to process customers in a first-come basis (FIFO). So the LinkedHashSet filfuls this requirement because it is also fast.

That's my interpretation anyway.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steven Young:
Yea, I got this question wrong as well. I chose the LinkedList for the collection to store customers applying for discount cards...


Hmmm... I probably would have gotten it wrong too. Did they offer any explanation with the answers? Are we to assume that each customer can make only one request for a discount card?

Anyway, expect the actual exam to be more clear about collection requirements (whether duplicates are acceptable, whether fast insertions/deletions from the middle are important, whether order matters, etc.).
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic