Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: having troubles in vector
|
Posted: Apr 11, 2002 12:11 PM
|
|
You obviously misapprehended the salient point: use an interface as the reference, not the concrete object's type, when possible. That is, use a List reference, whether the object is a Vector, ArrayList, LinkedList, or whatever. That makes for more flexible code.
As far as using a Vector versus an ArrayList or LinkedList, that is dependent on the problem at hand. You can often use any implementation of List and it will work; you will only really need to pick the right one if it starts causing performance problems (however, using the List interface as your reference will make it much easier to switch implementations). I would use an ArrayList for a simple list that may grow, a LinkedList for a list that may often have insertions and deletions at random locations and a Vector when I need it to be always serialized. So for a simple homework assignment type problem, I would use an ArrayList, since synchronizing data access is rarely a problem in single-threaded programs.
|
|