Things I Code

6Feb/120

Creating a pre-populated Vector

I came across a syntax for creating a pre-populated Vector object in ActionScript that I hadn't seen before.  It's all documented in the ActionScript reference, but I thought i'd make a note of it nevertheless.

Typically you create a new Vector object like this.

var v:Vector.<T> = new Vector.<T>();

Where you want to pre-populate the Vector at the time you create it, you can use this alternate syntax

var v:Vector.<String> = new <String>["item1","item2",];

Note the square brackets.  And that trailing comma is optional.

Just a neat bit of syntax that saves a bit of verbosity when setting up Vector objects.