5 Replies Latest reply: Jan 22, 2004 3:06 PM by 807582 RSS

    Vector example

    807582
      hi
      i need an example using Vector collection to ensure its synchroniztion
      thanx
        • 1. Re: Vector example
          807582
          all methods of class vector are synchnized .you have nothing to do
          • 2. Re: Vector example
            800387
            And don't use Vector. If you want List/Vector behavior, try the following:

            List foo = Collections.synchronizedList(new ArrayList());

            ArrayList has better performance.

            - Saish

            "My karma ran over your dogma." - Anon
            • 3. Re: Vector example
              807582
              ArrayList has better performance than Vector because it's not synchronized.
              • 4. Re: Vector example
                800387
                Probably true. Feel free to omit the synchronizedList() method if desired. From Sun's collections tutorial:

                http://java.sun.com/developer/onlineTraining/collections/Collection.html#ListInterface

                A Vector is an historical collection class that acts like a growable array, but can store heterogeneous data elements. With the Java 2 SDK, version 2, the Vector class has been retrofitted into the Collections Framework hierarchy to implement the List interface. However, if you are using the new framework, you should use ArrayList, instead.

                - Saish

                "My karma ran over your dogma." - Anon
                • 5. Re: Vector example
                  807582
                  I remember reading that performance is better if you use Vector instead of using Collections.synchronizedList(new ArrayList())

                  I am not 100 % sure though