• 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
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

OCP 8 Study Guide - ch3 - LinkedList is also a Queue, so what?

 
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From chapter 3, Review question #1:

Suppose that you have a collection of products for sale in a database and you need to display those products. The products are not unique. Which of the following collection classes in the package best suit your needs for this scenario?
A. Arrays
B. ArrayList
C. HashMap
D. HashSet
E. LinkedList



My answer: A,E
Correct answer:A

According to the solution

"LinkedList is both a list and a Queue"

, and no further explanation is given.

In my opinion LinkedList is perfectly fine for the job, and you would chose it over ArrayList if you needed to access it in a sequential manner rather than randomly. Which would be the case if there was a GUI showing the products in a form style, like Access does (there is a database, so why wouldn't there be a GUI?). Now for a normal console printout, granted it would be less performant, but there are other questions where Vector is shown to implement List as well, albeit it has all the synchronization overweight, and is given as valid, so I think any List would be a correct answer here, considering the question has multiple possible answers.
The excuse given in the answer, that LinkedList does not qualify for being also a Queue, is a poor one, for we don't care which other functionality does a class offer as long as it covers our use case.

I find this answer arbitrary and unfair. I really hope Oracle doesn't come up with questions like these in the real exam.
 
John Schubert
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I meant correct answer is B and I chose B and E (why can't I edit my own post?)

John Schubert wrote:From chapter 3, Review question #1:

Suppose that you have a collection of products for sale in a database and you need to display those products. The products are not unique. Which of the following collection classes in the package best suit your needs for this scenario?
A. Arrays
B. ArrayList
C. HashMap
D. HashSet
E. LinkedList



My answer: A,E
Correct answer:A

According to the solution

"LinkedList is both a list and a Queue"

, and no further explanation is given.

In my opinion LinkedList is perfectly fine for the job, and you would chose it over ArrayList if you needed to access it in a sequential manner rather than randomly. Which would be the case if there was a GUI showing the products in a form style, like Access does (there is a database, so why wouldn't there be a GUI?). Now for a normal console printout, granted it would be less performant, but there are other questions where Vector is shown to implement List as well, albeit it has all the synchronization overweight, and is given as valid, so I think any List would be a correct answer here, considering the question has multiple possible answers.
The excuse given in the answer, that LinkedList does not qualify for being also a Queue, is a poor one, for we don't care which other functionality does a class offer as long as it covers our use case.

I find this answer arbitrary and unfair. I really hope Oracle doesn't come up with questions like these in the real exam.

 
author & internet detective
Posts: 42148
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,
This question asks for the best data structure, not the best two data structures. ArrayList is more performant than LinkedList for accessing arbitrary elements. It is also the default choice of data structure if you don't have reasons to use another.

If I was picking two answers, LinkedList would be my second choice. But most professional programmers would choose ArrayList over LinkedList if there wasn't a reason to choose LinkedList. So I stand by the answer in the book.

Thanks for asking!
 
reply
    Bookmark Topic Watch Topic
  • New Topic