Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Chapter 3, Review question #1, Java OCP 8 Programmer II Study Guide

Ranch Hand
Posts: 135
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Ranchers!

The very first question of the review questions section in chapter 3 says,

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 collections classes in the java.util package best suit your needs for this scenario?

A. Arrays
B. ArrayList
C. HashMap
D. HashSet
E. LinkedList

My answer was (B,E). But the correct answer is marked only for (B). The explanation given is not clear about why we eliminated the LinkedList from the answers.

Explanation as follows:
The answer needs to implement List because the scenario allows duplicates. Since you need a List, you can eliminate C, D and E immediately. HashMap is a Map and HashSet is a Set. LinkedList is both a List and a Queue.

Yes, LinkedList can act as both a List and a Queue. So, LinkedList can be a List. It also can be a queue. Both List and Queue allow duplicates. If we are looking for a List, then why LinkedList (which is qualified as a List) is removed?  
Ranch Hand
Posts: 145
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I agree . It probably another error from OCP by Sybex
author & internet detective
Posts: 40035
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not an errata. The question asks which class *best* suits your needs. The idea was to choose one that best suits your needs. ArrayList is better than LinkedList if you don't need the Queue functionality because it will be faster.

I agree the explanation could have been clearer.
We're all out of roofs. But we still have tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic