Synchronized collections everywhere

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);

2 Responses to “Synchronized collections everywhere”

  1. LinkedLists as arrays « Java AntiPatterns Says:

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

  2. Alexwebmaster Says:

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

Leave a Reply