• 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

Q about Dan's Mock Exam

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Question 18
In addition to implementing the List interface, which of the following also provides methods to get, insert, and remove elements from the head and tail of the list?
a. Collection
b. ArrayList
c. LinkedList
d. List
e. Vector
f. None of the above
Answer:
c LinkedList The LinkedList provides methods that facilitate the implementation of stacks and queues.


I don't understand why b and e are incorrect? I think they also meet the requirements of the question:
1. ArrayList and Vector both implements the List interface
2. Both have the method get that can get elements from head and tail. In addition, Vector has the methods firstElement() and lastElement.
3. Both have a method add that can add elemenent at the beginning and end of the list
4. Both have a method remove that can remove element at the beginning and end of the list.
So what am I missing?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you, Alton. As the question is stated, Vector and ArrayList meet the requirements specified. However, I think Dan was really trying to get at the fact that LinkedList has methods such as addFirst, addLast, getFirst, etc. Perhaps it could be reworded to say something like:
"...and also allow you to add, get, and remove elements from the beginning or the end without specifying an index."
I hope that helps,
Corey
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alton,
I find your reasoning to be sound. LinkedList does explicitly declare
getFirst(), getLast(), removeFirst(), and removeLast() though, ArrayList and Vector also fit the apparent context of the question. As you already stated...
What I find is that the question is asking if you read:

In addition to implementing the List interface, the LinkedList class provides uniformly named methods to get, remove and insert an element at the beginning and end of the list.


in the JavaDoc for LinkedList.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic