i am interested in using a String array as an element in a Vector object. The array will always be of length 2. Is there a better way for this data structure? Reason for using the Vector is because of dynamic resizing, ie the number of elements vary and i would like to use the add and trimToSize methods for Vector.
Thanks!
Use
ArrayListand a custom object instead.Then to use it:
Vectoris no longer considered a good dynamic array in Java because of extra synchronization logic that’s more or less useless, so it just adds unnecessary overhead.ArrayListis the go-to dynamic array. You could also useLinkedList, which is a doubly-linked list.Of course, you should also use better naming conventions that describe what the values actually mean instead of the names that I used in my example.