This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Q about Dan's Mock Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Q about Dan Watch "Q about Dan New topic
Author

Q about Dan's Mock Exam

Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443

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

Joined: Dec 20, 2001
Posts: 3271
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


SCJP Tipline, etc.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q about Dan's Mock Exam
 
Similar Threads
new SCJP in town :)
in case of fast array or link list
ArrayList vs java.awt.List
Vectors/Arrays/List?