5 Replies Latest reply: Sep 26, 2008 1:40 AM by 843785 RSS

    vector or list which ihas a better performance ?

    843785
      Hi guys,
      The resultset of a select query has some 50,000 rows.I want to store it to do some further calculation.So should i go for vector or should i go for ArrayList?Which will be faster and will consume less memory or which will be better in performance.Can anyone advice me?
        • 1. Re: vector or list which ihas a better performance ?
          843785
          While it doesn't say explicitly, it seems like Vector implements an array-backed list similar to what ArrayList does. My guess is that you will not notice any difference between the two of them.

          If you're concerned with speed, both of them are the correct choice, particularly in this case, where you do not need to expand the array beyond the initial number of rows. Make sure when you declare your ArrayList or Vector that you specify the initial size to be the same as your that from your ResultSet. This prevents the ArrayList/Vector from having to resize itself when you add more stuff than it can handle at the time (both a time and memory-costly operation). Since both ArrayList and Vector are array-based, they're both fast for later sorting/reference operations. (You just don't want a linked list implementation!)

          You might also want to consider an array for your purposes, if you don't need the added functionality that the data structures provide. It makes for a bit more lightweight implementation.

          Frankly, though, you shouldn't have to worry too much with only 50,000 elements (unless they're all huge blobs or something).

          ~ Anthop
          • 2. Re: vector or list which ihas a better performance ?
            PhHein
            Ok, first do a search ArrayList vs. Vector. We had so many threads about this.

            If you aren't using a multi threaded environment go for ArrayList, otherwise use a Vector.
            • 3. Re: vector or list which ihas a better performance ?
              843785
              Oh that's right. PhHein is correct. A Vector is a synchronized data structure so it is better for multi-threaded applications where many threads need to concurrently access and modify the Vector. I'm not sure if this incurs a performance cost.
              • 4. Re: vector or list which ihas a better performance ?
                843785
                Anthop wrote:
                I'm not sure if this incurs a performance cost.
                It does, a slight one. But Vector is also an outdated class and it's preferred to use ArrayList, or when needing a synchronized list, using Collections.synchronizedList() to create one out of an ArrayList (or any list that suits you).
                • 5. Re: vector or list which ihas a better performance ?
                  843785
                  Thanks a lot guys....I will surely go for ArrayList.Untill i come up with any further queries or issues "HAPPY CODINGGG..."