Vector.<> vs array

Ilya Boyandin picture Ilya Boyandin · Jul 15, 2009 · Viewed 7.9k times · Source

What are the pros and contras of using a Vector.<> instead of array?

Answer

Arno picture Arno · Jul 15, 2009

From the adobe documentation page:

As a result of its restrictions, a Vector has two primary benefits over an Array instance whose elements are all instances of a single class:

  • Performance: array element access and iteration are much faster when using a Vector instance than when using an Array.
  • Type safety: in strict mode the compiler can identify data type errors such as assigning a value of the incorrect data type to a Vector or expecting the wrong data type when reading a value from a Vector. Note, however, that when using the push() method or unshift() method to add values to a Vector, the arguments' data types are not checked at compile time but are checked at run time.