# Class List

- [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)
    - [dw.util.List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)

An ordered collection of objects. The user of a List has precise control over
where in the list each element is inserted. The user can access elements by
their integer index (position in the list), and search for elements in the
list. Lists are zero based similar to arrays. Unlike sets, lists allow
duplicate elements.

## All Known Subclasses

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

## Property Summary

| Property                                                                                                 | Description                                            |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| [EMPTY_LIST](#empty_list): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md) | Convenience variable, for an empty and immutable list. |

## Constructor Summary

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

## Method Summary

| Method                                                                                                                                                                                                                                                                              | Description                                                                                                                                                       |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [addAt](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#addatnumber-object)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))           | Adds the specified object into the list at the specified index.                                                                                                   |
| [concat](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#concatobject)([Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                 | Creates and returns a new List that is the result of concatenating this  list with each of the specified values.                                                  |
| [fill](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#fillobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                        | Replaces all of the elements in the list with the given object.                                                                                                   |
| [get](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#getnumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))                                                                                                          | Returns the object at the specified index.                                                                                                                        |
| [indexOf](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#indexofobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                  | Returns the index of the first occurrence of the specified element in  this list, or -1 if this list does not contain the element.                                |
| [join](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#join)()                                                                                                                                                                                                | Converts all elements of the list to a string by calling the toString()  method and then concatenates them together, with a comma between  elements.              |
| [join](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#joinstring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md))                                                                                                        | Converts all elements of the list to a string by calling the toString()  method and then concatenates them together, with the separator string  between elements. |
| [lastIndexOf](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#lastindexofobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                          | Returns the index of the last occurrence of the specified element in this  list, or -1 if this list does not contain the element.                                 |
| [pop](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#pop)()                                                                                                                                                                                                  | Removes and returns the last element from the list.                                                                                                               |
| [push](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#pushobject)([Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                     | Appends the specified values to the end of the list in order.                                                                                                     |
| [removeAt](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#removeatnumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))                                                                                                | Removes the object at the specified index.                                                                                                                        |
| [replaceAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#replaceallobject-object)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md), [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)) | Replaces all occurrences of oldValue with newValue.                                                                                                               |
| [reverse](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#reverse)()                                                                                                                                                                                          | Reverses the order of the elements in the list.                                                                                                                   |
| [rotate](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#rotatenumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))                                                                                                    | Rotates the elements in the list by the specified distance.                                                                                                       |
| [set](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#setnumber-object)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))               | Replaces the object at the specified index in this list with the specified object.                                                                                |
| [shift](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#shift)()                                                                                                                                                                                              | Removes and returns the first element of the list.                                                                                                                |
| [shuffle](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#shuffle)()                                                                                                                                                                                          | Randomly permutes the elements in the list.                                                                                                                       |
| [size](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#size)()                                                                                                                                                                                                | Returns the size of this list.                                                                                                                                    |
| [slice](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#slicenumber)([Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md))                                                                                                      | Returns a slice, or sublist, of this list.                                                                                                                        |
| [slice](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#slicenumber-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 slice, or sublist, of this list.                                                                                                                        |
| [sort](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#sort)()                                                                                                                                                                                                | Sorts the elements of the list based on their natural  order.                                                                                                     |
| [sort](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#sortobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                                        | Sorts the elements of a list.                                                                                                                                     |
| [subList](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#sublistnumber-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 list containing the elements in this list identified  by the specified arguments.                                                                       |
| [swap](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#swapnumber-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))             | Swaps the elements at the specified positions in the list.                                                                                                        |
| [unshift](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md#unshiftobject)([Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))                                                                                               | Inserts values at the beginning of the list.                                                                                                                      |

### Methods inherited from class Collection

[add](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#addobject), [add1](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#add1object), [addAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#addallcollection), [clear](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#clear), [contains](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#containsobject), [containsAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#containsallcollection), [getLength](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#getlength), [isEmpty](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#isempty), [iterator](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#iterator), [remove](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#removeobject), [removeAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#removeallcollection), [retainAll](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#retainallcollection), [size](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#size), [toArray](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#toarray), [toArray](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.Collection.md#toarraynumber-number)

### 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_LIST

- EMPTY_LIST: [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)
  - : Convenience variable, for an empty and immutable list.

***

## Method Details

### addAt(Number, Object)

- addAt(index: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), value: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): void
  - : Adds the specified object into the list at the specified index.

    **Parameters:**

    - index - the index to use.
    - value - the object to insert.

***

### concat(Object...)

- concat(values: [Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)
  - : Creates and returns a new List that is the result of concatenating this
    list with each of the specified values. This list itself is unmodified.
    If any of the specified values is itself an array or a Collection, then
    the elements of that Collection or array are appended to the new list
    rather than the object itself.

    **Parameters:**

    - values - one or more objects to concatenate.

    **Returns:**

    - a new List that is the result of concatenating this
      list with each of the specified values.

***

### fill(Object)

- fill(obj: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): void
  - : Replaces all of the elements in the list with the given object.

    **Parameters:**

    - obj - the object to use during replacement.

***

### get(Number)

- get(index: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - : Returns the object at the specified index.

    **Parameters:**

    - index - the index to use.

    **Returns:**

    - the object at the specified index.

***

### indexOf(Object)

- indexOf(value: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the index of the first occurrence of the specified element in
    this list, or -1 if this list does not contain the element.

    **Parameters:**

    - value - the element to use.

    **Returns:**

    - the index of the specified object or -1 if the passed object is
      not found in the list.

***

### join()

- join(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Converts all elements of the list to a string by calling the toString()
    method and then concatenates them together, with a comma between
    elements.

    **Returns:**

    - The string that results from converting each element of the list
      to a string and then concatenating them together, with a comma
      between elements.

***

### join(String)

- join(separator: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Converts all elements of the list to a string by calling the toString()
    method and then concatenates them together, with the separator string
    between elements. If null is passed, then the comma character is used as
    a separator.

    **Parameters:**

    - separator - The separator string. May be null in which case the             comma character is used.

    **Returns:**

    - The string that results from converting each element of the list
      to a string and then concatenating them together, with the
      separator string between elements.

***

### lastIndexOf(Object)

- lastIndexOf(value: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the index of the last occurrence of the specified element in this
    list, or -1 if this list does not contain the element.

    **Parameters:**

    - value - the element to use.

    **Returns:**

    - the last index of the specified object or -1 if the passed object
      is not found in the list.

***

### pop()

- pop(): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - : Removes and returns the last element from the list.

    **Returns:**

    - The last element of the list or null if the list is already
      empty.

***

### push(Object...)

- push(values: [Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Appends the specified values to the end of the list in order.

    **Parameters:**

    - values - One or more values to be appended to the end of the list.

    **Returns:**

    - The new length of the list, after the specified values are
      appended to it.

***

### removeAt(Number)

- removeAt(index: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - : Removes the object at the specified index.

    **Parameters:**

    - index - the index to use.

    **Returns:**

    - the object that was removed.

***

### replaceAll(Object, Object)

- replaceAll(oldValue: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md), newValue: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Replaces all occurrences of oldValue with newValue.

    **Parameters:**

    - oldValue - the old object.
    - newValue - the new object.

    **Returns:**

    - true if one or more elements were replaced, false otherwise.

***

### reverse()

- reverse(): void
  - : Reverses the order of the elements in the list.

***

### rotate(Number)

- rotate(distance: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): void
  - : Rotates the elements in the list by the specified distance.

    **Parameters:**

    - distance - the distance to use.

***

### set(Number, Object)

- set(index: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), value: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - : Replaces the object at the specified index in this list with the specified object.

    **Parameters:**

    - index - the index to use.
    - value - the object to use when replacing the existing object.

    **Returns:**

    - the replaced object.

***

### shift()

- shift(): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - : Removes and returns the first element of the list. If the list is already
    empty, this method simply returns null.

    **Returns:**

    - The former first element of the list, or null is list is already
      empty.

***

### shuffle()

- shuffle(): void
  - : Randomly permutes the elements in the list.

***

### size()

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

    **Returns:**

    - the size of this list.

***

### slice(Number)

- slice(from: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)
  - : Returns a slice, or sublist, of this list. The returned list contains the
    element specified by `from` and all subsequent elements up to
    the end of this list.

    **Parameters:**

    - from - The index at which the slice is to begin. If negative, this             argument specifies a position measured from the end of this             list. That, -1 indicates the last element, -2 indicates the             next from the last element, and so on.

    **Returns:**

    - A new List that contains the elements of this list from the
      element specified by `from` up to the end of this
      list.

***

### slice(Number, Number)

- slice(from: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), to: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)
  - : Returns a slice, or sublist, of this list. The returned list contains the
    element specified by `from` and all subsequent elements up to,
    but not including, the element specified by `to`.

    **Parameters:**

    - from - The index at which the slice is to begin. If negative, this             argument specifies a position measured from the end of this             list. That, -1 indicates the last element, -2 indicates the             next from the last element, and so on.
    - to - The index immediately after the end of the slice. If this             argument is negative, it specifies an element measured from             the end of this list.

    **Returns:**

    - A new List that contains the elements of this list from the
      element specified by `from` up to, but not including,
      the element specified by `to`.

***

### sort()

- sort(): void
  - : Sorts the elements of the list based on their natural
    order.

    This sort is guaranteed to be *stable*:  equal elements will
    not be reordered as a result of the sort.

***

### sort(Object)

- sort(comparator: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): void
  - : Sorts the elements of a list. The order of the elements is
    determined with a comparator (see PropertyComparator) or with the help
    of the given function. The function must take two parameters and return
    a value <0 if the first parameter is smaller than the second, a value
    of 0 if both are equal and a value if >0 if the first one is greater
    than the second parameter.

    This sort is guaranteed to be *stable*:  equal elements will
    not be reordered as a result of the sort.

    **Parameters:**

    - comparator - an instance of a PropertyComparator or a comparison function

***

### subList(Number, Number)

- subList(from: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), to: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): [List](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.util.List.md)
  - : Returns a list containing the elements in this list identified
    by the specified arguments.

    **Parameters:**

    - from - the beginning index of the elements to move to the new list.
    - to - the ending index of the elements to move to the new list.

    **Returns:**

    - the new list containing the elements.

***

### swap(Number, Number)

- swap(i: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md), j: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)): void
  - : Swaps the elements at the specified positions in the list.

    **Parameters:**

    - i - the first element to swap.
    - j - the second element to swap.

***

### unshift(Object...)

- unshift(values: [Object...](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Inserts values at the beginning of the list.  The first argument
    becomes the new element 0;  the second argument becomes element 1;
    and so on.

    **Parameters:**

    - values - The values to insert into the list.

    **Returns:**

    - The new length of the lest.

***
