JavaAntiPatterns

Collection of bad coding practices

Synchronized collections everywhere

with 2 comments

Vector and Hashtable are just the synchronized versions of the ArrayList an HashMap but working much slower. Use unsynchronized collections unless thread-safety is really required.

Bad:

List l = new Vector();
for (...)
    l.add(anObject);

Good:

List l = new ArrayList();
for (...)
    l.add(anObject);
Advertisements

Written by Alex

November 22, 2007 at 11:21 am

Posted in Collections

Tagged with , , ,

2 Responses

Subscribe to comments with RSS.

  1. […] ArrayList (or Vector if synchronization is required) for random-accessed […]

  2. Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

    Alexwebmaster

    March 3, 2009 at 11:56 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: