# Class Collection

- [TopLevel.Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - [dw.util.Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md)

Represents a collection of objects.

## All Known Subclasses

[ArrayList](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.ArrayList.md), [FilteringCollection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.FilteringCollection.md), [HashSet](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.HashSet.md), [LinkedHashSet](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.LinkedHashSet.md), [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md), [Set](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Set.md), [SortedSet](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.SortedSet.md)

## Property Summary

| Property                                                                                                            | Description                              |
| ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| [empty](#empty): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md) `(read-only)` | Returns true if the collection is empty. |
| [length](#length): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md) `(read-only)` | Returns the length of the collection.    |

## Constructor Summary

This class does not have a constructor, so you cannot create it directly.

## Method Summary

| Method                                                                                                                                                                                                                                                                              | Description                                                                              |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| [add](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#addobject)([Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                 | Adds the specified objects to the collection.                                            |
| [add1](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#add1object)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                  | The method adds a single object to the collection.                                       |
| [addAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#addallcollection)([Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md))                                                                                   | Adds the collection of objects to the collection.                                        |
| [clear](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#clear)()                                                                                                                                                                                        | Clears the collection.                                                                   |
| [contains](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#containsobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                          | Returns true if the collection contains the specified object.                            |
| [containsAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#containsallcollection)([Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md))                                                                         | Returns true if the collection contains all of the objects  in the specified collection. |
| [getLength](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#getlength)()                                                                                                                                                                                | Returns the length of the collection.                                                    |
| [isEmpty](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#isempty)()                                                                                                                                                                                    | Returns true if the collection is empty.                                                 |
| [iterator](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#iterator)()                                                                                                                                                                                  | Returns an iterator that can be used to access  the members of the collection.           |
| [remove](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#removeobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                              | Removes the specified object from the collection.                                        |
| [removeAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#removeallcollection)([Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md))                                                                             | Removes all of object in the specified object from the collection.                       |
| [retainAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#retainallcollection)([Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md))                                                                             | Removes all of object in the collection that are not in the  specified collection.       |
| [size](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#size)()                                                                                                                                                                                          | Returns the size of the collection.                                                      |
| [toArray](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#toarray)()                                                                                                                                                                                    | Returns all elements of this collection in a newly created array.                        |
| [toArray](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#toarraynumber-number)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)) | Returns a subset of the elements of this collection in a newly created array.            |

### Methods inherited from class Object

[assign](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#assignobject-object), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject-object), [defineProperties](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertiesobject-object), [defineProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertyobject-object-object), [entries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#entriesobject), [freeze](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#freezeobject), [fromEntries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#fromentriesiterable), [getOwnPropertyDescriptor](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertydescriptorobject-object), [getOwnPropertyNames](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertynamesobject), [getOwnPropertySymbols](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertysymbolsobject), [getPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getprototypeofobject), [hasOwnProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#hasownpropertystring), [is](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isobject-object), [isExtensible](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isextensibleobject), [isFrozen](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isfrozenobject), [isPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isprototypeofobject), [isSealed](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#issealedobject), [keys](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#keysobject), [preventExtensions](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#preventextensionsobject), [propertyIsEnumerable](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#propertyisenumerablestring), [seal](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#sealobject), [setPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#setprototypeofobject-object), [toLocaleString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tolocalestring), [toString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tostring), [valueOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valueof), [values](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valuesobject)

## Property Details

### empty

- empty: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md) `(read-only)`
  - : Returns true if the collection is empty.

***

### length

- length: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md) `(read-only)`
  - : Returns the length of the collection. This is similar to
    to a ECMA array of 'products.length'.

***

## Method Details

### add(Object...)

- add(values: [Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Adds the specified objects to the collection. The method can also
    be called with an ECMA array as argument.

    If called with a single ECMA array as argument the individual elements of
    that array are added to the collection. If the array object itself should
    be added use the method add1().

    **Parameters:**

    - values - the values to add.

    **Returns:**

    - true if the values were added, false otherwise.

***

### add1(Object)

- add1(object: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : The method adds a single object to the collection.

    **Parameters:**

    - object - the object to add.

    **Returns:**

    - true if the object was added, false otherwise.

***

### addAll(Collection)

- addAll(objs: [Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Adds the collection of objects to the collection.

    **Parameters:**

    - objs - the objects to add.

    **Returns:**

    - true if the objects were added, false otherwise.

***

### clear()

- clear(): void
  - : Clears the collection.

***

### contains(Object)

- contains(obj: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns true if the collection contains the specified object.

    **Parameters:**

    - obj - the object to locate in this collection.

    **Returns:**

    - true if the collection contains the specified object,
      false otherwise.

***

### containsAll(Collection)

- containsAll(objs: [Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns true if the collection contains all of the objects
    in the specified collection.

    **Parameters:**

    - objs - the collection of objects to locate in this collection.

    **Returns:**

    - true if the collection contains all of the specified objects,
      false otherwise.

***

### getLength()

- getLength(): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the length of the collection. This is similar to
    to a ECMA array of 'products.length'.

    **Returns:**

    - the length of the collection.

***

### isEmpty()

- isEmpty(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Returns true if the collection is empty.

    **Returns:**

    - true if the collection is empty, false otherwise

***

### iterator()

- iterator(): [Iterator](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Iterator.md)
  - : Returns an iterator that can be used to access
    the members of the collection.

    **Returns:**

    - an iterator that can be used to access
      the members of the collection.

***

### remove(Object)

- remove(obj: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Removes the specified object from the collection.

    **Parameters:**

    - obj - the object to remove.

    **Returns:**

    - true if the specified object was removed,
      false otherwise.

***

### removeAll(Collection)

- removeAll(objs: [Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Removes all of object in the specified object from the collection.

    **Parameters:**

    - objs - the collection of objects to remove.

    **Returns:**

    - true if the all of the specified objects were removed,
      false otherwise.

***

### retainAll(Collection)

- retainAll(objs: [Collection](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Removes all of object in the collection that are not in the
    specified collection.

    **Parameters:**

    - objs - the collection of objects to retain in the collection.

    **Returns:**

    - true if the collection retains all of the specified objects,
      false otherwise.

***

### size()

- size(): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the size of the collection.

    **Returns:**

    - the size of the collection.

***

### toArray()

- toArray(): [Array](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Array.md)
  - : Returns all elements of this collection in a newly created array. The returned array is independent of this collection and
    can be modified without changing the collection. The elements in the array are in the same order as they are returned when
    iterating over this collection.

    **Returns:**

    - a newly created array.

***

### toArray(Number, Number)

- toArray(start: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), size: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [Array](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Array.md)
  - : Returns a subset of the elements of this collection in a newly created array. The returned array is independent of this collection and
    can be modified without changing the collection. The elements in the array are in the same order as they are returned when
    iterating over this collection.

    **Parameters:**

    - start - the number of elements to iterate before adding elements to             the array. Negative values are treated as 0.
    - size - the maximum number of elements to add to the array.             Nonpositive values always result in empty array.

    **Returns:**

    - a newly created array.

***
