• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q about Dan's Mock Exam

 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • 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?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • 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
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic