未验证 提交 201db129 编写于 作者: O openharmony_ci 提交者: Gitee

!13720 翻译完成:13084 语言基础类库API全量更新

Merge pull request !13720 from wusongqing/TR13084
# @ohos.util.ArrayList (Linear Container ArrayList)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**ArrayList** is a linear data structure that is implemented based on arrays. **ArrayList** can dynamically adjust the capacity based on project requirements. It increases the capacity by 50% each time.
......@@ -42,7 +41,7 @@ A constructor used to create an **ArrayList** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -77,7 +76,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -113,12 +112,12 @@ Inserts an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -151,7 +150,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -188,7 +187,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -230,7 +229,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -272,12 +271,12 @@ Removes an element with the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -313,7 +312,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -347,12 +346,12 @@ Removes from this container all of the elements within a range, including the el
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByRange method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
......@@ -391,7 +390,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -426,7 +425,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
| callbackFn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
......@@ -439,7 +438,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -481,7 +480,7 @@ comparator
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -523,12 +522,12 @@ Obtains elements within a range in this container, including the element at the
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The subArrayList method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
......@@ -553,7 +552,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -587,7 +586,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -620,7 +619,7 @@ Obtains the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -653,7 +652,7 @@ Converts this container into an array.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -686,7 +685,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -719,7 +718,7 @@ Increases the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -747,7 +746,7 @@ Trims the capacity of this container to its current length.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -780,7 +779,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.Deque (Linear Container Deque)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Double-ended queue (deque) is a sequence container implemented based on the queue data structure that follows the principles of First In First Out (FIFO) and Last In First Out (LIFO). It allows insertion and removal of elements at both the ends. **Deque** can dynamically adjust the capacity based on project requirements. It doubles the capacity each time. **Deque** differs from **[Queue](js-apis-queue.md)** and **[Vector](js-apis-vector.md)** mainly in the following aspects:
......@@ -41,7 +40,7 @@ A constructor used to create a **Deque** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -69,7 +68,7 @@ Inserts an element at the front of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -104,7 +103,7 @@ Inserts an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -145,7 +144,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -172,11 +171,11 @@ Removes the first element of this container.
| Type| Description|
| -------- | -------- |
| T | Element removed.|
| T | First element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -206,11 +205,11 @@ Removes the last element of this container.
| Type| Description|
| -------- | -------- |
| T | Element removed.|
| T | Last element removed.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -254,7 +253,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -289,7 +288,7 @@ Obtains the first element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -322,7 +321,7 @@ Obtains the last element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -355,7 +354,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.HashMap (Nonlinear Container HashMap)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashMap** is a map implemented based on the array, linked list, and red-black tree. It provides efficient data query, insertion, and removal. The elements in a **HashMap** instance are mappings of key-value pairs. Each key must be unique and have only one value.
......@@ -43,7 +42,7 @@ A constructor used to create a **HashMap** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -72,7 +71,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -108,7 +107,7 @@ Checks whether this container contains the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -146,7 +145,7 @@ Checks whether this container contains the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -184,7 +183,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -216,7 +215,7 @@ Adds all elements in a **HashMap** instance to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -256,7 +255,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -292,7 +291,7 @@ Removes an element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -318,7 +317,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -350,7 +349,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -387,7 +386,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -431,7 +430,7 @@ Replaces an element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -470,7 +469,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -504,7 +503,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -542,14 +541,13 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The Symbol.iterator method cannot be bound. |
**Example**
```ts
let hashMap = new HashMap();
hashMap.set("squirrel", 123);
......
# @ohos.util.HashSet (Nonlinear Container HashSet)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**HashSet** is implemented based on [HashMap](js-apis-hashmap.md). In **HashSet**, only the **value** object is processed.
......@@ -51,7 +50,7 @@ A constructor used to create a **HashSet** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -80,7 +79,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -116,7 +115,7 @@ Checks whether this container contains the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -154,7 +153,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -190,7 +189,7 @@ Removes an element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -216,7 +215,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -248,7 +247,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -293,7 +292,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -326,7 +325,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -364,7 +363,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.LightWeightMap (Nonlinear Container LightWeightMap)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
**LightWeightMap** is based on generics and uses a lightweight structure. Keys in the map are searched using hash values, which are stored in an array.
**LightWeightMap** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
The keys in such a set are searched using hash values, which are stored in an array.
Compared with **[HashMap](js-apis-hashmap.md)**, which can also store KV pairs, **LightWeightMap** occupies less memory.
......@@ -44,7 +45,7 @@ A constructor used to create a **LightWeightMap** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -73,7 +74,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -109,7 +110,7 @@ Checks whether this container contains all elements of the specified **LightWeig
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -149,7 +150,7 @@ Checks whether this container contains the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -159,10 +160,8 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er
```ts
let lightWeightMap = new LightWeightMap();
let result = lightWeightMap.hasKey;
lightWeightMap.hasKey("squirrel");
lightWeightMap.set("squirrel", 123);
let result1 = lightWeightMap.hasKey("squirrel");
let result = lightWeightMap.hasKey("squirrel");
```
......@@ -188,7 +187,7 @@ Checks whether this container contains the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -214,7 +213,7 @@ Increases the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -256,7 +255,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -294,7 +293,7 @@ Obtains the index of the first occurrence of an element with the specified key i
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -332,7 +331,7 @@ Obtains the index of the first occurrence of an element with the specified value
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -370,12 +369,12 @@ Obtains the key of an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getKeyAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -403,7 +402,7 @@ Adds all elements in a **LightWeightMap** instance to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -416,7 +415,7 @@ let lightWeightMap = new LightWeightMap();
lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sparrow", 356);
let map = new LightWeightMap();
lightWeightMap.setAll(map);
map.setAll(lightWeightMap); // Add all elements in lightWeightMap to the map.
```
......@@ -442,7 +441,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -478,7 +477,7 @@ Removes an element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -516,7 +515,7 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -555,12 +554,12 @@ Sets a value for an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -594,12 +593,12 @@ Obtains the value of an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -621,7 +620,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -653,7 +652,7 @@ Obtains an iterator that contains all the keys in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -690,7 +689,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -735,7 +734,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -769,7 +768,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -800,13 +799,13 @@ Concatenates the elements in this container into a string and returns the string
**Return value**
| Type| Description|
| -------- | -------- |
| String | String obtained.|
| Type| Description|
| -------- | -------- |
| String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -818,7 +817,7 @@ For details about the error codes, see [containers Error Codes](../errorcodes/er
let lightWeightMap = new LightWeightMap();
lightWeightMap.set("squirrel", 123);
lightWeightMap.set("sparrow", 356);
let iter = lightWeightMap.toString();
let result = lightWeightMap.toString();
```
### [Symbol.iterator]
......@@ -837,7 +836,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.LightWeightSet (Nonlinear Container LightWeightSet)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LightWeightSet** stores a set of values, each of which must be unique.
......@@ -44,7 +43,7 @@ A constructor used to create a **LightWeightSet** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -73,7 +72,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -108,7 +107,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -138,7 +137,7 @@ Adds all elements in a **LightWeightSet** instance to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -178,7 +177,7 @@ Checks whether this container contains all elements of the specified **LightWeig
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -218,7 +217,7 @@ Checks whether this container has the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -246,7 +245,7 @@ Checks whether this container contains objects of the same type as the specified
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| obj | Object | Yes| Object to be used for comparison.|
| obj | Object | Yes| **LightWeightSet** instance to be used for comparison.|
**Return value**
......@@ -256,7 +255,7 @@ Checks whether this container contains objects of the same type as the specified
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -289,12 +288,12 @@ Increases the capacity of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The increaseCapacityTo method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of minimumCapacity is out of range. |
**Example**
......@@ -326,7 +325,7 @@ Obtains the position index of the element with the specified key in this contain
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -364,7 +363,7 @@ Removes an element of the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -402,7 +401,7 @@ Removes the element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -440,7 +439,7 @@ Obtains the value of the element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -466,7 +465,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -496,14 +495,6 @@ Obtains a string that contains all elements in this container.
| -------- | -------- |
| String | String obtained.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The toString method cannot be bound. |
**Example**
```ts
......@@ -530,7 +521,7 @@ Obtains an array that contains all objects in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -562,7 +553,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -607,7 +598,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -641,7 +632,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -678,7 +669,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.LinkedList (Linear Container LinkedList)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**LinkedList** is implemented based on the doubly linked list. Each node of the doubly linked list has references pointing to the previous element and the next element. When querying an element, the system traverses the list from the beginning or end. **LinkedList** offers efficient insertion and removal operations but supports low query efficiency. **LinkedList** allows null elements.
Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList** is a doubly linked list that supports insertion and removal at both ends.
**LinkedList** is less efficient in data access than **[ArrayList](js-apis-arraylist.md)**.
**LinkedList** is more efficient in data insertion than **[ArrayList](js-apis-arraylist.md)**, but less efficient in data access.
**Recommended use case**: Use **LinkedList** for frequent insertion and removal operations.
......@@ -42,7 +41,7 @@ A constructor used to create a **LinkedList** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -78,7 +77,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -113,7 +112,7 @@ Adds an element at the top of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -149,12 +148,12 @@ Inserts an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -187,7 +186,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -224,7 +223,7 @@ Obtains an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -266,7 +265,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -308,7 +307,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -350,12 +349,12 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -385,7 +384,7 @@ Removes the first element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -420,7 +419,7 @@ Removes the last element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -461,7 +460,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -500,7 +499,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -540,7 +539,7 @@ Removes the last occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -574,7 +573,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -617,7 +616,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -646,7 +645,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -686,12 +685,12 @@ Replaces an element at the specified position in this container with a given ele
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The set method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -720,7 +719,7 @@ Converts this container into an array.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -752,7 +751,7 @@ Obtains the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -785,7 +784,7 @@ Obtains the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -818,7 +817,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.List (Linear Container List)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**List** is implemented based on the singly linked list. Each node has a reference pointing to the next element. When querying an element, the system traverses the list from the beginning. **List** offers efficient insertion and removal operations but supports low query efficiency. **List** allows null elements.
......@@ -16,7 +15,7 @@ This topic uses the following to identify the use of generics:
## Modules to Import
```ts
import List from '@ohos.util.List';
import List from '@ohos.util.List';
```
......@@ -26,7 +25,7 @@ import List from '@ohos.util.List';
**System capability**: SystemCapability.Utils.Lang
| Name| Type | Readable| Writable| Description|
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| length | number | Yes| No| Number of elements in a list (called container later).|
......@@ -41,7 +40,7 @@ A constructor used to create a **List** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -76,7 +75,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -112,12 +111,12 @@ Inserts an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The insert method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -150,7 +149,7 @@ Checks whether this container has the specified element.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -187,7 +186,7 @@ Obtains the element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -229,7 +228,7 @@ Obtains the index of the last occurrence of the specified element in this contai
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -271,7 +270,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -314,7 +313,7 @@ Compares whether a specified object is equal to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -359,12 +358,12 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeByIndex method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -400,7 +399,7 @@ Removes the first occurrence of the specified element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -443,7 +442,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -478,7 +477,7 @@ Uses a callback to traverse the elements in this container and obtain their posi
| Name| Value Type | Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the elements in the container.|
| callbackFn | function | Yes| Callback invoked for the replacement.|
| thisArg | Object | No| Value to use when the callback is invoked.|
callbackfn
......@@ -491,7 +490,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -533,7 +532,7 @@ comparator
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -547,8 +546,8 @@ list.add(2);
list.add(4);
list.add(5);
list.add(4);
list.sort((a: number, b: number) => a - b);
list.sort((a: number, b: number) => b - a);
list.sort((a: number, b: number) => a - b); // The elements are sorted in ascending order.
list.sort((a: number, b: number) => b - a); // The elements are sorted in descending order.
```
### getSubList
......@@ -574,12 +573,12 @@ Obtains elements within a range in this container, including the element at the
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getSubList method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of fromIndex or toIndex is out of range. |
**Example**
......@@ -604,7 +603,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -644,12 +643,12 @@ Replaces an element at the specified position in this container with a given ele
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The set method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -678,7 +677,7 @@ Converts this container into an array.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -711,7 +710,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -744,7 +743,7 @@ Obtains the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -777,7 +776,7 @@ Obtains the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -810,7 +809,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.PlainArray (Nonlinear Container PlainArray)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**PlainArray** stores key-value (KV) pairs. Each key must be unique, be of the number type, and have only one value.
......@@ -21,6 +20,8 @@ This topic uses the following to identify the use of generics:
import PlainArray from '@ohos.util.PlainArray';
```
## PlainArray
### Attributes
......@@ -42,7 +43,7 @@ A constructor used to create a **PlainArray** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -71,7 +72,7 @@ Checks whether this container is empty.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -107,7 +108,7 @@ Checks whether this container contains the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -145,7 +146,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -183,7 +184,7 @@ Obtains the index of the first occurrence of an element with the specified key i
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -221,7 +222,7 @@ Obtains the index of the first occurrence of an element with the specified value
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -259,7 +260,7 @@ Obtains the key of the element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -284,24 +285,24 @@ Obtains the value of an element at the specified position in this container.
**Parameters**
| Name| Type | Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.|
| Name| Type | Mandatory| Description|
| -------- | -------- | -------- | -------- |
| index | number | Yes| Position index of the target element.|
**Return value**
| Type| Description|
| -------- | -------- |
| T | Returns the value of the element if obtained; returns **undefined** otherwise.|
| Type| Description|
| -------- | -------- |
| T | Returns the value of the element if obtained; returns **undefined** otherwise.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The getValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -328,7 +329,7 @@ Clones this container and returns a copy. The modification to the copy does not
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -361,7 +362,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -397,7 +398,7 @@ Removes an element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -435,7 +436,7 @@ Removes an element at the specified position from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -474,12 +475,12 @@ Removes elements in a specified range from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The removeRangeFrom method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -508,12 +509,12 @@ Sets a value for an element at the specified position in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200011 | The setValueAt method cannot be bound. |
| 10200001 | The parameter value is out of range. |
| 10200001 | The value of index is out of range. |
**Example**
......@@ -541,7 +542,7 @@ Obtains a string that contains all elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -567,7 +568,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -607,7 +608,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -641,7 +642,7 @@ Obtains an iterator object that contains key-value pairs, where the key is of th
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.Queue (Linear Container Queue)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Queue** follows the principle of First In First Out (FIFO). It supports insertion of elements at the end and removal from the front of the queue. **Queue** is implemented based on the queue data structure.
......@@ -41,7 +40,7 @@ A constructor used to create a **Queue** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -76,7 +75,7 @@ Adds an element at the end of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -110,7 +109,7 @@ Removes the first element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -144,7 +143,7 @@ Obtains the first element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -187,7 +186,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -222,7 +221,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.Stack (Linear Container Stack)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**Stack** is implemented based on the array data structure. It follows the principle Last Out First In (LOFI) and supports data insertion and removal at one end.
......@@ -40,7 +39,7 @@ A constructor used to create a **Stack** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -75,7 +74,7 @@ Adds an element at the top of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -109,7 +108,7 @@ Removes the top element from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -143,7 +142,7 @@ Obtains the top element of this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -182,7 +181,7 @@ Obtains the index of the first occurrence of the specified element in this conta
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -225,7 +224,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -260,7 +259,7 @@ Checks whether this container is empty (contains no elements).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -293,7 +292,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.TreeMap (Nonlinear Container TreeMap)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeMap** stores key-value (KV) pairs. Each key must be unique and have only one value.
......@@ -49,7 +48,7 @@ A constructor used to create a **TreeMap** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -78,7 +77,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -114,7 +113,7 @@ Checks whether this container has the specified key.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -152,7 +151,7 @@ Checks whether this container has the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -190,7 +189,7 @@ Obtains the value of the specified key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -222,7 +221,7 @@ Obtains the first key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -254,7 +253,7 @@ Obtains the last key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -282,11 +281,11 @@ Adds all elements in a **TreeMap** instance to this container.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| map | TreeMap<K, V> | Yes| **TreeMap** instance whose elements are to be added to the current container.|
| map | TreeMap<K, V> | Yes| **TreeMap** object to be added to the container.|
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -299,7 +298,11 @@ let treeMap = new TreeMap();
treeMap.set("squirrel", 123);
treeMap.set("sparrow", 356);
let map = new TreeMap();
treeMap.setAll(map);
map.set("demo", 12);
map.setAll(treeMap); // Add all elements in the treeMap to the map.
map.forEach((value, key) => {
console.log("test" + value, key); // Print result: 12 demo, 356 sparrow, and 123 squirrel
})
```
......@@ -326,7 +329,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -362,7 +365,7 @@ Removes the element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -400,7 +403,7 @@ Obtains the key that is placed in front of the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -439,7 +442,7 @@ Obtains the key that is placed next to the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -478,7 +481,7 @@ Replaces an element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -503,7 +506,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -535,7 +538,7 @@ Obtains an iterator that contains all the keys in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -572,7 +575,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -617,7 +620,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -651,7 +654,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -688,7 +691,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
# @ohos.util.TreeSet (Nonlinear Container TreeSet)
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
**TreeSet** is implemented based on **[TreeMap](js-apis-treemap.md)**. In **TreeSet**, only **value** objects are processed. **TreeSet** can be used to store values, each of which must be unique.
......@@ -46,7 +45,7 @@ A constructor used to create a **TreeSet** instance.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -75,7 +74,7 @@ Checks whether this container is empty (contains no element).
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -111,7 +110,7 @@ Checks whether this container has the specified value.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -143,7 +142,7 @@ Obtains the value of the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -175,7 +174,7 @@ Obtains the value of the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -213,7 +212,7 @@ Adds an element to this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -249,7 +248,7 @@ Removes the element with the specified key from this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -287,7 +286,7 @@ Obtains the value that is placed in front of the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -326,7 +325,7 @@ Obtains the value that is placed next to the input key in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -359,7 +358,7 @@ Removes the first element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -391,7 +390,7 @@ Removes the last element in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -417,7 +416,7 @@ Clears this container and sets its length to **0**.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -449,7 +448,7 @@ Obtains an iterator that contains all the values in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -494,7 +493,7 @@ callbackfn
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -528,7 +527,7 @@ Obtains an iterator that contains all the elements in this container.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......@@ -566,7 +565,7 @@ Obtains an iterator, each item of which is a JavaScript object.
**Error codes**
For details about the error codes, see [containers Error Codes](../errorcodes/errorcode-containers.md).
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
......
......@@ -29,6 +29,70 @@ import uri from '@ohos.uri'
| authority | string | Yes| No| Authority part in the URI.|
| ssp | string | Yes| No| Scheme-specific part in the URI.|
### Naming Rules
Naming format:
A standard URI consists of the following parts:
[scheme:]scheme-specific-part[#fragment]
- Scheme: scheme component, which is mandatory. Example values: **http**, **https**, **ftp**, **datashare**, and **dataability**.
- scheme-specific-part: specific part of the URI decoding scheme. The value consists of [//][authority][path][?query]. Set this parameter as required.
- authority: decoding authority component of the URI. The value consists of [userinfo@]host[:port]. Set this parameter as required.
- userinfo: user information. Set this parameter as required.
- host: host name of the server. This parameter is mandatory when authority exists.
- port: port number of the server. Set this parameter as required.
- path: path information. Set this parameter as required.
- query: query component. Set this parameter as required.
- fragment: fragment component. Set this parameter as required.
**Example URIs**
```js
const result1 = new uri.URI("ftp://ftp.aaa.bbb.ccc/dddd/eee.txt");
console.log(result1.host) // ftp.aaa.bbb.ccc
console.log(result1.fragment) // null
console.log(result1.path) // /dddd/eee.txt
console.log(result1.scheme) // ftp
console.log(result1.userInfo) // null
console.log(result1.port) // -1
console.log(result1.query) // null
const result2 = new uri.URI("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#fragment");
console.log(result2.host) // spinaltap.micro.umn.edu
console.log(result2.fragment) // fragment
console.log(result2.path) // /dddd/eee.txt
console.log(result2.scheme) // ftp
console.log(result2.userInfo) // null
console.log(result2.port) //-1
console.log(result2.query) // null
const result3 = new uri.URI("datashare:///com.samples.datasharetest.DataShare/DB00/TBL00");
console.log(result3.host) // null
console.log(result3.fragment) // null
console.log(result3.path) // /com.samples.datasharetest.DataShare/DB00/TBL00
console.log(result3.scheme) // datashare
console.log(result3.userInfo) // null
console.log(result3.port) // -1
console.log(result3.query) // null
const result4 = new uri.URI("https://username:password@host:8080/directory/file?foo=1&bar=2#fragment");
console.log(result4.host) // host
console.log(result4.fragment) // fragment
console.log(result4.path) // /directory/file
console.log(result4.scheme) // https
console.log(result4.userInfo) // username:password
console.log(result4.port) // 8080
console.log(result4.query) // foo=1&bar=2
const result5 = new uri.URI("dataability:///com.example.DataAbility");
console.log(result5.host) // null
console.log(result5.fragment) // null
console.log(result5.path) // /com.example.DataAbility:
console.log(result5.scheme) // dataability
console.log(result5.userInfo) // null
console.log(result5.port) // -1
console.log(result5.query) // null
```
### constructor
......@@ -44,6 +108,14 @@ A constructor used to create a URI instance.
| -------- | -------- | -------- | -------- |
| uri | string | Yes| Input object.|
**Error codes**
For details about the error codes, see [Utils Error Codes](../errorcodes/errorcode-utils.md).
| ID| Error Message|
| -------- | -------- |
| 10200002 | Invalid uri string. |
**Example**
```js
......@@ -79,14 +151,14 @@ result.toString()
### equals<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [equalsTo<sup>9+</sup>](#equalsto9) instead.
equals(other: URI): boolean
Checks whether this URI is the same as another URI object.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [equalsTo<sup>9+</sup>](#equalsto9) instead.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
......@@ -105,7 +177,7 @@ Checks whether this URI is the same as another URI object.
```js
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equals(uriInstance1);
```
### equalsTo<sup>9+</sup>
......@@ -132,7 +204,7 @@ Checks whether this URI is the same as another URI object.
```js
const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equalsTo(uriInstance1);
```
......@@ -148,7 +220,7 @@ Checks whether this URI is an absolute URI (whether the scheme component is defi
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the URI is an absolute URI; returns **false** otherwise.|
| boolean | If the URI is an absolute URI, **true** is returned. Otherwise, **false** is returned.|
**Example**
......
......@@ -11,7 +11,6 @@ import Url from '@ohos.url'
```
## URLParams<sup>9+</sup>
### constructor<sup>9+</sup>
constructor(init?: string[][] | Record&lt;string, string&gt; | string | URLSearchParams)
......@@ -32,7 +31,7 @@ A constructor used to create a **URLParams** instance.
let objectParams = new Url.URLParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]);
let objectParams1 = new Url.URLParams({"fod" : '1' , "bard" : '2'});
let objectParams2 = new Url.URLParams('?fod=1&bard=2');
let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2');
let urlObject = Url.URL.parseURL('https://developer.mozilla.org/?fod=1&bard=2');
let params = new Url.URLParams(urlObject.search);
```
......@@ -55,7 +54,7 @@ Appends a key-value pair into the query string.
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.append('fod', '3');
```
......@@ -78,9 +77,9 @@ Deletes key-value pairs of the specified key.
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsobject = new Url.URLParams(urlObject.search.slice(1));
paramsobject.delete('fod');
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.delete('fod');
```
......@@ -88,7 +87,7 @@ paramsobject.delete('fod');
getAll(name: string): string[]
Obtains all the key-value pairs based on the specified key.
Obtains all the key-value pairs based on the specified name.
**System capability**: SystemCapability.Utils.Lang
......@@ -102,12 +101,12 @@ Obtains all the key-value pairs based on the specified key.
| Type| Description|
| -------- | -------- |
| string[] | All key-value pairs matching the specified key.|
| string[] | Key-value pairs obtained.|
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(urlObject.search.slice(1));
params.append('fod', '3'); // Add a second value for the fod parameter.
console.log(params.getAll('fod').toString()) // Output ["1","3"].
......@@ -132,7 +131,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
```js
let searchParamsObject = new Url.URLParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
for (var pair of searchParamsObject.entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]);
}
```
......@@ -164,9 +163,9 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal
**Example**
```js
const myURLObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.searchParams.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.searchParams === searchParams);
const myURLObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
myURLObject.params.forEach((value, name, searchParams) => {
console.log(name, value, myURLObject.params === searchParams);
});
```
......@@ -224,7 +223,7 @@ Checks whether a key has a value.
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.has('bard') === true;
```
......@@ -248,7 +247,7 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t
**Example**
```js
let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let urlObject = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let paramsObject = new Url.URLParams(urlObject.search.slice(1));
paramsObject.set('baz', '3'); // Add a third parameter.
```
......@@ -360,7 +359,7 @@ Obtains search parameters that are serialized as a string and, if necessary, per
**Example**
```js
let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2');
let url = Url.URL.parseURL('https://developer.exampleUrl/?fod=1&bard=2');
let params = new Url.URLParams(url.search.slice(1));
params.append('fod', '3');
console.log(params.toString());
......@@ -384,20 +383,20 @@ console.log(params.toString());
| port | string | Yes| Yes| Port in a URL.|
| protocol | string | Yes| Yes| Protocol in a URL.|
| search | string | Yes| Yes| Serialized query string in a URL.|
| searchParams | URLSearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.|
| URLParams | URLParams | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| searchParams<sup>(deprecated)</sup> | [URLSearchParams](#urlsearchparamsdeprecated) | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.<br>- **NOTE**: This attribute is supported since API version 7 and is deprecated since API version 9. You are advised to use params<sup>9+</sup> instead.|
| params<sup>9+</sup> | [URLParams](#urlparams9) | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| username | string | Yes| Yes| Username in a URL.|
### constructor<sup>(deprecated)</sup>
constructor(url: string, base?: string | URL)
Creates a URL.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [parseURL<sup>9+</sup>](#parseurl9) instead.
constructor(url: string, base?: string | URL)
Creates a URL.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
......@@ -410,13 +409,13 @@ Creates a URL.
**Example**
```js
let mm = 'http://username:password@host:8080';
let a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/';
let b = new Url.URL(mm); // Output 'http://username:password@host:8080/';
new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1';
let c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1';
new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1';
new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1';
let mm = 'https://username:password@host:8080';
let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/';
let b = new Url.URL(mm); // Output 'https://username:password@host:8080/';
new Url.URL('path/path1', b); // Output 'https://username:password@host:8080/path/path1';
let c = new Url.URL('/path/path1', b); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', c); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', a); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1
new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL
new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
......@@ -424,8 +423,16 @@ new Url.URL('https://www.example.com', ); // Output https://www.example.com/
new Url.URL('https://www.example.com', b); // Output https://www.example.com/
```
### parseURL<sup>9+</sup>
### constructor<sup>9+</sup>
constructor()
A no-argument constructor used to create a URL. It returns a **URL** object after **parseURL** is called. It is not used independently.
**System capability**: SystemCapability.Utils.Lang
### parseURL<sup>9+</sup>
static parseURL(url : string, base?: string | URL): URL
Parses a URL.
......@@ -447,11 +454,13 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
| -------- | -------- |
| 10200002 | Invalid url string. |
**Example**
```js
let mm = 'http://username:password@host:8080';
Url.URL.parseURL(mm); // Output 'http://username:password@host:8080/';
let mm = 'https://username:password@host:8080';
let url = Url.URL.parseURL(mm);
url.toString(); // Output 'https://username:password@host:8080/';
```
### tostring
......@@ -471,11 +480,10 @@ Converts the parsed URL into a string.
**Example**
```js
const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString();
```
### toJSON
toJSON(): string
......@@ -492,7 +500,7 @@ Converts the parsed URL into a JSON string.
**Example**
```js
const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const url = Url.URL.parseURL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON();
```
......@@ -634,7 +642,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th
```js
let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2");
for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs
for (var pair of searchParamsObject.entries()) { // Show keyName/valueName pairs
console.log(pair[0]+ ', '+ pair[1]);
}
```
......@@ -657,7 +665,7 @@ Traverses the key-value pairs in the **URLSearchParams** instance by using a cal
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callbackFn | function | Yes| Callback invoked to traverse the key-value pairs in the **URLSearchParams** instance.|
| thisArg | Object | No| Value to use when **callbackFn** is invoked.|
| thisArg | Object | No| Value of **this** to use when **callbackFn** is invoked.|
**Table 1** callbackFn parameter description
......@@ -902,126 +910,4 @@ let params = new Url.URLSearchParams(url.search.slice(1));
params.append('fod', '3');
console.log(params.toString());
```
## URL
### Attributes
**System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| hash | string | Yes| Yes| String that contains a harsh mark (#) followed by the fragment identifier of a URL.|
| host | string | Yes| Yes| Host information in a URL.|
| hostname | string | Yes| Yes| Hostname (without the port) in a URL.|
| href | string | Yes| Yes| String that contains the whole URL.|
| origin | string | Yes| No| Read-only string that contains the Unicode serialization of the origin of the represented URL.|
| password | string | Yes| Yes| Password in a URL.|
| pathname | string | Yes| Yes| Path in a URL.|
| port | string | Yes| Yes| Port in a URL.|
| protocol | string | Yes| Yes| Protocol in a URL.|
| search | string | Yes| Yes| Serialized query string in a URL.|
| searchParams | URLSearchParams | Yes| No| **URLSearchParams** object allowing access to the query parameters in a URL.|
| URLParams | URLParams | Yes| No| **URLParams** object allowing access to the query parameters in a URL.|
| username | string | Yes| Yes| Username in a URL.|
### constructor<sup>(deprecated)</sup>
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [parseURL<sup>9+</sup>](#parseurl9) instead.
constructor(url: string, base?: string | URL)
Creates a URL.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| url | string | Yes| Input object.|
| base | string \| URL | No| Input parameter, which can be any of the following:<br>- **string**: string<br>- **URL**: string or object|
**Example**
```js
let mm = 'https://username:password@host:8080';
let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/';
let b = new Url.URL(mm); // Output 'https://username:password@host:8080/';
new Url.URL('path/path1', b); // Output 'https://username:password@host:8080/path/path1';
let c = new Url.URL('/path/path1', b); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', c); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', a); // Output 'https://username:password@host:8080/path/path1';
new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1
new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL
new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL
new Url.URL('https://www.example.com', ); // Output https://www.example.com/
new Url.URL('https://www.example.com', b); // Output https://www.example.com/
```
### parseURL<sup>9+</sup>
static parseURL(url : string, base?: string | URL): URL
Parses a URL.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| url | string | Yes| Input object.|
| base | string \| URL | No| Input parameter, which can be any of the following:<br>- **string**: string<br>- **URL**: string or object|
**Example**
```js
let mm = 'https://username:password@host:8080';
Url.URL.parseURL(mm); // Output 'https://username:password@host:8080/';
```
### tostring
toString(): string
Converts the parsed URL into a string.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| string | Website address in a serialized string.|
**Example**
```js
const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString();
```
### toJSON
toJSON(): string
Converts the parsed URL into a JSON string.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| string | Website address in a serialized string.|
**Example**
```js
const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toJSON();
```
<!--no_check-->
# @ohos.zlib
# @ohos.zlib (Zip)
The **zlib** module provides APIs for file compression and decompression.
The **Zip** module provides APIs for file compression and decompression.
> **NOTE**
>
......@@ -25,7 +25,7 @@ Zips a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to zip. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to zip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the zipped file. The file name extension is .zip. |
| options | [Options](#options) | Yes | Optional parameters for the zip operation. |
......@@ -39,6 +39,7 @@ Zips a file. This API uses a promise to return the result.
```typescript
// Zip a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xxx/filename.xxx';
let outFile = '/xxx/xxx.zip';
......@@ -59,6 +60,7 @@ zlib.zipFile(inFile, outFile, options).then((data) => {
```typescript
// Zip a folder.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xxx/xxx';
let outFile = '/xxx/xxx.zip';
......@@ -89,7 +91,7 @@ Unzips a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to unzip. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to unzip. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the unzipped file. |
| options | [Options](#options) | Yes | Optional parameters for the unzip operation. |
......@@ -103,6 +105,7 @@ Unzips a file. This API uses a promise to return the result.
```typescript
// Unzip a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip';
let outFile = '/xxx';
......@@ -131,7 +134,7 @@ Compresses a file. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to compress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the compressed file. |
| options | [Options](#options) | Yes | Compression parameters. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
......@@ -141,14 +144,14 @@ Compresses a file. This API uses an asynchronous callback to return the result.
For details about the error codes, see [zlib Error Codes](../errorcodes/errorcode-zlib.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 900001 | The Input source file is invalid. |
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
**Example**
```typescript
// Compress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xxx/filename.xxx';
let outFile = '/xxx/xxx.zip';
......@@ -179,7 +182,7 @@ Compresses a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the folder or file to compress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the folder or file to compress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the compressed file. |
| options | [Options](#options) | Yes | Compression parameters. |
......@@ -189,12 +192,12 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| ID| Error Message |
| -------- | ------------------------------------- |
| 900001 | The Input source file is invalid. |
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
```typescript
// Compress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xxx/filename.xxx';
let outFile = '/xxx/xxx.zip';
......@@ -229,7 +232,7 @@ Decompresses a file. This API uses an asynchronous callback to return the result
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to decompress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. |
| options | [Options](#options) | Yes | Decompression parameters. |
| AsyncCallback<**void**> | callback | No | Callback used to return the result. If the operation is successful, **null** is returned; otherwise, a specific error code is returned. |
......@@ -240,14 +243,14 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| ID| Error Message
| -------- | --------------------------------------|
| 900001 | The Input source file is invalid. |
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
**Example**
```typescript
// Decompress a file.
// The path used in the code must be the application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip';
let outFile = '/xxx';
......@@ -270,7 +273,7 @@ try {
decompressFile(inFile: string, outFile: string, options: Options): Promise\<void>;
Decompress a file. This API uses a promise to return the result.
Decompresses a file. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.Zlib
......@@ -278,7 +281,7 @@ Decompress a file. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------------------- | ---- | ------------------------------------------------------------ |
| inFile | string | Yes | Path of the file to decompress. For details about the path, see [FA Model](js-apis-inner-app-context.md) or [Stage Model](js-apis-application-context.md).|
| inFile | string | Yes | Path of the file to decompress. The path must be an application sandbox path, which can be obtained from the context. For details about the context, see [FA Model](js-apis-inner-app-context.md) and [Stage Model] (js-apis-application-context.md).|
| outFile | string | Yes | Path of the decompressed file. |
| options | [Options](#options) | Yes | Decompression parameters. |
......@@ -288,12 +291,12 @@ For details about the error codes, see [zlib Error Codes](../errorcodes/errorcod
| ID| Error Message |
| ------ | ------------------------------------- |
| 900001 | The Input source file is invalid. |
| 900002 | The Input destination file is invalid. |
| 900001 | The input source file is invalid. |
| 900002 | The input destination file is invalid. |
```typescript
// Decompress a file.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through context.
// The path used in the code must be an application sandbox path, for example, /data/storage/el2/base/haps. You can obtain the path through the context.
import zlib from '@ohos.zlib';
let inFile = '/xx/xxx.zip';
let outFile = '/xxx';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册