Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

when is Vector appropiate?
I notice some examples on the web use Vectors; here they're pretty
universally derided.  If an ArrayList is synchronized how different is it
from a Vector?  Treating each as a black box, is the only difference
performance?


thanks,

Thufir Hawat
still pondering generics

Report this thread to moderator Post Follow-up to this message
Old Post
thufir.hawat@mail.com
07-29-04 02:09 AM


Re: when is Vector appropiate?
thufir.hawat@mail.com wrote:
> I notice some examples on the web use Vectors; here they're pretty
> universally derided.  If an ArrayList is synchronized how different is it
> from a Vector?  Treating each as a black box, is the only difference
> performance?

First of all, I will assume you meant "If I synchronize an ArrayList
using Collections.synchronizedList, ...".  If you really meant "Since an
ArrayList is synchronized..." then I would feel the need to point out
that there is absolutely no synchronization in ArrayList by default.

Second, yes that's basically it; ArrayList and Vector are functionally
identical.  Their performance is not even likely to be all that
different.  There are a couple reasons to choose ArrayList over Vector,
though:

1. It's idiomatic.  It follows the typical Collections API usage to a T,
whereas Vector was retrofitted.  The default synchronized behavior is
one example of a place where Vector was forced to differ with typical
collections because of backward compatibility.  It also has the
confusing dual names for methods that do the same thing (addElement vs.
add, for example), and isn't named according to the typical naming
convention of the Collections API.

2. It's more consistent to use ArrayList all the time rather than switch
back and forth depending on your need for synchronized blocks (which is
really the only reason you'd switch).  Collections.synchronizedList may
look more complex, but not when you consider that you use almost
identical code to synchronize a Map or Set as well.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Smith
07-29-04 02:09 AM


Re: when is Vector appropiate?
On Tue, 27 Jul 2004, Chris Smith wrote:
> First of all, I will assume you meant "If I synchronize an ArrayList
> using Collections.synchronizedList, ...".  If you really meant "Since an
> ArrayList is synchronized..." then I would feel the need to point out
> that there is absolutely no synchronization in ArrayList by default.

oops, yes I meant *if*, thanks.

> Second, yes that's basically it; ArrayList and Vector are functionally
> identical.  Their performance is not even likely to be all that
> different.  There are a couple reasons to choose ArrayList over Vector,
> though:
>
> 1. It's idiomatic.  It follows the typical Collections API usage to a T,
> whereas Vector was retrofitted.  The default synchronized behavior is
> one example of a place where Vector was forced to differ with typical
> collections because of backward compatibility.  It also has the
> confusing dual names for methods that do the same thing (addElement vs.
> add, for example), and isn't named according to the typical naming
> convention of the Collections API.
>
> 2. It's more consistent to use ArrayList all the time rather than switch
> back and forth depending on your need for synchronized blocks (which is
> really the only reason you'd switch).  Collections.synchronizedList may
> look more complex, but not when you consider that you use almost
> identical code to synchronize a Map or Set as well.
>
> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation
>

makes sense, thanks.

Thufir Hawat
<http://www.shaw.ca/members/hawat/source/>

Report this thread to moderator Post Follow-up to this message
Old Post
thufir.hawat@mail.com
07-29-04 02:09 AM


Re: when is Vector appropiate?
Chris Smith <cdsmith@twu.net> wrote:
> 2. It's more consistent to use ArrayList all the time rather than switch
> back and forth depending on your need for synchronized blocks (which is
> really the only reason you'd switch).  Collections.synchronizedList may
> look more complex, but not when you consider that you use almost
> identical code to synchronize a Map or Set as well.

Also, the only thing that needs to change is the creation of the object.
That is, assuming you follow the expectations of the collections framework
and use List as the object type.


--
Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2

Report this thread to moderator Post Follow-up to this message
Old Post
Oscar kind
07-29-04 02:09 AM


Re: when is Vector appropiate?
"Chris Smith" <cdsmith@twu.net> wrote in message
news:MPG.1b7096c066cf8d11989751@news.altopia.net...
>
> 2. It's more consistent to use ArrayList all the time rather than switch
> back and forth depending on your need for synchronized blocks (which is
> really the only reason you'd switch).  Collections.synchronizedList may
> look more complex, but not when you consider that you use almost
> identical code to synchronize a Map or Set as well.
>
> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation



Report this thread to moderator Post Follow-up to this message
Old Post
Shane Mingins
07-29-04 02:09 AM


Re: when is Vector appropiate?
"Chris Smith" <cdsmith@twu.net> wrote in message
news:MPG.1b7096c066cf8d11989751@news.altopia.net...
> Second, yes that's basically it; ArrayList and Vector are functionally
> identical.  Their performance is not even likely to be all that
> different.  There are a couple reasons to choose ArrayList over Vector,
> though:

Don't u hate it when u accidentally hit send before you've typed your
message :-(  Ignore my other non-reply!

JList supports a Vector as it's list data ... so I find I am creating/using
Vectors for that ... just wondered if I may have been missing something
there?

Cheers
Shane


--
"Dear Lord: The gods have been good to me. For the first time in my life,
everything is absolutely perfect just the way it is. So here's the deal: You
freeze everything the way it is, and I won't ask for anything more. If that
is OK, please give me absolutely no sign. OK, deal. In gratitude, I present
you this offering of cookies and milk. If you want me to eat them for you,
give me no sign. Thy will be done."  - Homer Simpson



Report this thread to moderator Post Follow-up to this message
Old Post
Shane Mingins
07-29-04 02:09 AM


Re: when is Vector appropiate?
When you must support a pre-1.2 VM.
The same can be said for java.util.Hashtable

--
Tony Morris
http://xdweb.net/~dibblego/




Report this thread to moderator Post Follow-up to this message
Old Post
Tony Morris
07-31-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:32 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.