The asdk.algorithm.Copying
class provides two static functions for copying elements between collections. The primary
function, copy
, takes a source collection, a destination collection and a start and end index as parameters. The example below
demonstrates using this method to combine a CD collection with a DVD collection into a new disc collection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
var cdCollection:asdk.Collection = new asdk.ArrayList(); |
The code above creates two ArrayList collections and populates each with some CD (lines 1-4) and DVD (lines 6-8) titles. The important lines are 11 and 12 where the contents of cdCollection and dvdCollection are copied into the newly minted discCollection. Note that the copy method does not return a value, but instead copies the values into the discCollection array that is passed in to the method as the destination (2nd) parameter.
The other static function that is surfaced in the Copying class is copyBackward
which will copy elements into
the destination collection in reverse order. The example below is similar to the previous example except that copyBackward is
called. Note here that the resulting collection looks like [Van Halen,Pink Floyd,Cold Play,The Count of Monte Cristo,Braveheart]
since both collections were copied in reverse order.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
var cdCollection:asdk.Collection = new asdk.ArrayList(); |