diff --git a/en/application-dev/reference/apis/js-apis-arraylist.md b/en/application-dev/reference/apis/js-apis-arraylist.md index ebf538d3b5508c1ee26aa77d4db01aa995239c3b..283786a82fd1ce50d7632b9354b99f32ff4419fb 100644 --- a/en/application-dev/reference/apis/js-apis-arraylist.md +++ b/en/application-dev/reference/apis/js-apis-arraylist.md @@ -404,11 +404,9 @@ arrayList.add(2); arrayList.add(4); arrayList.add(5); arrayList.add(4); -arrayList.replaceAllElements((value: number, index: number)=> { - return value = 2 * value; -}); -arrayList.replaceAllElements((value: number, index: number) => { - return value = value - 2; +arrayList.replaceAllElements((value) => { + // Add the user operation logic based on the actual scenario. + return value; }); ``` @@ -453,7 +451,7 @@ arrayList.add(4); arrayList.add(5); arrayList.add(4); arrayList.forEach((value, index) => { - console.log(`value:${value}`, index); + console.log("value:" + value, "index:" + index); }); ``` @@ -796,14 +794,14 @@ arrayList.add(4); // Method 1: for (let item of arrayList) { - console.log(`value:${item}`); + console.log(`value:${item}`); } // Method 2: let iter = arrayList[Symbol.iterator](); let temp = iter.next().value; while(temp != undefined) { - console.log(`value:${temp}`); - temp = iter.next().value; + console.log(`value:${temp}`); + temp = iter.next().value; } ``` diff --git a/en/application-dev/reference/apis/js-apis-deque.md b/en/application-dev/reference/apis/js-apis-deque.md index 274836333aa773d32a386ad22b03706e890859c7..46d97bd96c27c9d3f05d519ebde6ff1ed8d3e4c5 100644 --- a/en/application-dev/reference/apis/js-apis-deque.md +++ b/en/application-dev/reference/apis/js-apis-deque.md @@ -1,9 +1,5 @@ # @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: **Queue** follows the principle of FIFO only and allows element removal at the front and insertion at the rear. @@ -15,6 +11,11 @@ Double-ended queue (deque) is a sequence container implemented based on the queu This topic uses the following to identify the use of generics: - T: Type +> **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. + + ## Modules to Import ```ts @@ -269,7 +270,7 @@ deque.insertEnd(4); deque.insertFront(5); deque.insertEnd(4); deque.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-hashmap.md b/en/application-dev/reference/apis/js-apis-hashmap.md index d39dbd1e6649359d5e6433fe11b0a2d68febf953..807394ad4538e34997ac5b5eb917e47aad295161 100644 --- a/en/application-dev/reference/apis/js-apis-hashmap.md +++ b/en/application-dev/reference/apis/js-apis-hashmap.md @@ -1,8 +1,5 @@ # @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. **HashMap** is faster in accessing data than **[TreeMap](js-apis-treemap.md)**, because the former accesses the keys based on the hash codes, whereas the latter stores and accesses the keys in sorted order. @@ -15,6 +12,11 @@ This topic uses the following to identify the use of generics: - K: Key - V: Value +> **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. + + ## Modules to Import ```ts @@ -482,7 +484,7 @@ let hashMap = new HashMap(); hashMap.set("sparrow", 123); hashMap.set("gull", 357); hashMap.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-hashset.md b/en/application-dev/reference/apis/js-apis-hashset.md index f2ece05248321395e2ca3f651ff32a462503d5c4..8d21ef6d1994144aeb89be8d226ef041bdbdb95a 100644 --- a/en/application-dev/reference/apis/js-apis-hashset.md +++ b/en/application-dev/reference/apis/js-apis-hashset.md @@ -305,7 +305,7 @@ let hashSet = new HashSet(); hashSet.add("sparrow"); hashSet.add("squirrel"); hashSet.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-lightweightmap.md b/en/application-dev/reference/apis/js-apis-lightweightmap.md index 89893c1c97d183c69765535141b2012fae9e080a..057dc7e3f1f52f8d491ed1edf35037d42c7ee337 100644 --- a/en/application-dev/reference/apis/js-apis-lightweightmap.md +++ b/en/application-dev/reference/apis/js-apis-lightweightmap.md @@ -747,7 +747,7 @@ let lightWeightMap = new LightWeightMap(); lightWeightMap.set("sparrow", 123); lightWeightMap.set("gull", 357); lightWeightMap.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-lightweightset.md b/en/application-dev/reference/apis/js-apis-lightweightset.md index 25c7950dc4968bc3f9f33ad6b277ecdc68a6ea09..47295b0dd86d5b805607850b92a9692f71940dc7 100644 --- a/en/application-dev/reference/apis/js-apis-lightweightset.md +++ b/en/application-dev/reference/apis/js-apis-lightweightset.md @@ -611,7 +611,7 @@ let lightWeightSet = new LightWeightSet(); lightWeightSet.add("sparrow"); lightWeightSet.add("gull"); lightWeightSet.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-linkedlist.md b/en/application-dev/reference/apis/js-apis-linkedlist.md index bc51f25fbb6c54f7fadc6bdd05533113a1c7254c..ceb144301277ac8cdd08f52713ae6cf576817a18 100644 --- a/en/application-dev/reference/apis/js-apis-linkedlist.md +++ b/en/application-dev/reference/apis/js-apis-linkedlist.md @@ -1,8 +1,5 @@ # @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. @@ -14,6 +11,11 @@ Unlike **[List](js-apis-list.md)**, which is a singly linked list, **LinkedList* This topic uses the following to identify the use of generics: - T: Type +> **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. + + ## Modules to Import ```ts @@ -505,6 +507,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco | -------- | -------- | | 10200011 | The removeFirstFound method cannot be bound. | | 10200010 | Container is empty. | +| 10200017 | The element does not exist in this container. | **Example** @@ -545,6 +548,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco | -------- | -------- | | 10200011 | The removeLastFound method cannot be bound. | | 10200010 | Container is empty. | +| 10200017 | The element does not exist in this container. | **Example** @@ -631,7 +635,7 @@ linkedList.add(4); linkedList.add(5); linkedList.add(4); linkedList.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-list.md b/en/application-dev/reference/apis/js-apis-list.md index bd1272f3a7a48a47f30ba689ff9df972932727d6..295824f50139aca548f3dcd5952ce75c2bec7cfc 100644 --- a/en/application-dev/reference/apis/js-apis-list.md +++ b/en/application-dev/reference/apis/js-apis-list.md @@ -1,8 +1,5 @@ # @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. Unlike [LinkedList](js-apis-linkedlist.md), which is a doubly linked list, **List** is a singly linked list that does not support insertion or removal at both ends. @@ -12,6 +9,10 @@ Unlike [LinkedList](js-apis-linkedlist.md), which is a doubly linked list, **Lis This topic uses the following to identify the use of generics: - T: Type +> **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. + ## Modules to Import ```ts @@ -505,7 +506,7 @@ list.add(4); list.add(5); list.add(4); list.forEach((value, index) => { - console.log("value: " + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-plainarray.md b/en/application-dev/reference/apis/js-apis-plainarray.md index 8ccc7d7fb4bc1a5f876b8da75c181f8547e32f51..387577bb2409ae399f46a225e53e3d00db9035e6 100644 --- a/en/application-dev/reference/apis/js-apis-plainarray.md +++ b/en/application-dev/reference/apis/js-apis-plainarray.md @@ -621,7 +621,7 @@ let plainArray = new PlainArray(); plainArray.add(1, "squirrel"); plainArray.add(2, "sparrow"); plainArray.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-queue.md b/en/application-dev/reference/apis/js-apis-queue.md index e4adf559e862ddc954b7e75c3253fb8aa95b6b2a..56bb71d5b88e93c2364c23176543f131d134e9f2 100644 --- a/en/application-dev/reference/apis/js-apis-queue.md +++ b/en/application-dev/reference/apis/js-apis-queue.md @@ -201,7 +201,7 @@ queue.add(4); queue.add(5); queue.add(4); queue.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-stack.md b/en/application-dev/reference/apis/js-apis-stack.md index ff8551cad86f3f4c448e08d267548657305c5c9d..46b06f608af9615bbb138bc54d82cab7f566c0fa 100644 --- a/en/application-dev/reference/apis/js-apis-stack.md +++ b/en/application-dev/reference/apis/js-apis-stack.md @@ -239,7 +239,7 @@ stack.push(4); stack.push(5); stack.push(4); stack.forEach((value, index) => { - console.log("value:" + value, index); + console.log("value:" + value, "index:" + index); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-treemap.md b/en/application-dev/reference/apis/js-apis-treemap.md index eb874f0abd94f72f56f0e1e13a23883e1ae14ce8..473b5cb99e94c1ab84069d23591b63555bfcb7d5 100644 --- a/en/application-dev/reference/apis/js-apis-treemap.md +++ b/en/application-dev/reference/apis/js-apis-treemap.md @@ -1,8 +1,5 @@ # @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. **TreeMap** is implemented using a red-black tree, which is a binary search tree where keys are stored in sorted order for efficient insertion and removal. @@ -12,9 +9,15 @@ Recommended use case: Use **TreeMap** when you need to store KV pairs in sorted order. This topic uses the following to identify the use of generics: + - K: Key + - V: Value +> **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. + ## Modules to Import ```ts @@ -609,7 +612,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.| -| thisArg | Object | No| Value to use when the callback is invoked.| +| thisArg | Object | No| Value of **this** to use when **callbackFn** is invoked.| callbackfn | Name| Type| Mandatory| Description| @@ -633,7 +636,7 @@ let treeMap = new TreeMap(); treeMap.set("sparrow", 123); treeMap.set("gull", 357); treeMap.forEach((value, key) => { - console.log("value:" + value, key); + console.log("value:" + value, "key:" + key); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-treeset.md b/en/application-dev/reference/apis/js-apis-treeset.md index 4aaaac1861ceffdfda3d7adc53b16181c42cc9c3..5ca493adcae4ff144341f04d9d1641035ae98db8 100644 --- a/en/application-dev/reference/apis/js-apis-treeset.md +++ b/en/application-dev/reference/apis/js-apis-treeset.md @@ -1,8 +1,5 @@ # @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. **[HashSet](js-apis-hashset.md)** stores data in a random order, whereas **TreeSet** stores data in sorted order. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**. @@ -10,8 +7,13 @@ Recommended use case: Use **TreeSet** when you need to store data in sorted order. This topic uses the following to identify the use of generics: + - T: Type +> **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. + ## Modules to Import ```ts @@ -482,13 +484,13 @@ 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.| -| thisArg | Object | No| Value to use when the callback is invoked.| +| thisArg | Object | No| Value of **this** to use when **callbackFn** is invoked.| callbackfn | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | value | T | No| Value of the element that is currently traversed.| -| key | T | No| Key of the element that is currently traversed (same as **value**).| +| key | T | No| Key of the element that is currently traversed.| | set | TreeSet<T> | No| Instance that invokes the **forEach** method.| **Error codes** @@ -506,7 +508,7 @@ let treeSet = new TreeSet(); treeSet.add("sparrow"); treeSet.add("gull"); treeSet.forEach((value, key) => { - console.log("value:" + value, key) + console.log("value:" + value, "key:" + key); }); ``` diff --git a/en/application-dev/reference/apis/js-apis-vector.md b/en/application-dev/reference/apis/js-apis-vector.md index 302b8223c0b720390c82cb28afa921b439fef7fd..7e59a7685b38a014a76065ee04255b106c9d8133 100644 --- a/en/application-dev/reference/apis/js-apis-vector.md +++ b/en/application-dev/reference/apis/js-apis-vector.md @@ -1,9 +1,5 @@ # @ohos.util.Vector (Linear Container Vector) -> **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. - **Vector** is a linear data structure that is implemented based on arrays. When the memory of a vector is used up, a larger contiguous memory area is automatically allocated, all the elements are copied to the new memory area, and the current memory area is reclaimed. **Vector** can be used to efficiently access elements. Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based on arrays, but **Vector** provides more interfaces for operating the arrays. Both of them can dynamically adjust the capacity. **Vector** doubles the capacity each time, whereas **ArrayList** increases the capacity by 50%. @@ -13,6 +9,12 @@ Both **Vector** and **[ArrayList](js-apis-arraylist.md)** are implemented based This topic uses the following to identify the use of generics: - T: Type +> **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. +> +> The APIs provided by this module are deprecated since API version 9. You are advised to use [@ohos.util.ArrayList](js-apis-arraylist.md). + ## Modules to Import ```ts @@ -251,7 +253,7 @@ Removes the first occurrence of the specified element from this container. | -------- | -------- | | boolean | Returns **true** if the element is removed successfully; returns **false** otherwise.| -**Return value** +**Example** ```ts let vector = new Vector(); @@ -320,11 +322,9 @@ vector.add(2); vector.add(4); vector.add(5); vector.add(4); -vector.replaceAllElements((value: number, index: number) => { - return value = 2 * value; -}); -vector.replaceAllElements((value: number, index: number) => { - return value = value - 2; +vector.replaceAllElements((value) => { + // Add the user operation logic based on the actual scenario. + return value; }); ``` @@ -361,7 +361,7 @@ vector.add(4); vector.add(5); vector.add(4); vector.forEach((value, index) => { - console.log("value:" + value, index) + console.log("value:" + value, "index:" + index); }); ``` @@ -421,7 +421,7 @@ Obtains elements within a range in this container, including the element at the | -------- | -------- | | Vector<T> | New **Vector** instance obtained.| -**Return value** +**Example** ```ts let vector = new Vector(); @@ -444,7 +444,7 @@ Clears all elements in this container and sets its length to **0**. **System capability**: SystemCapability.Utils.Lang -**Return value** +**Example** ```ts let vector = new Vector(); @@ -639,18 +639,6 @@ Copies elements in this container into an array to overwrite elements of the sam | -------- | -------- | -------- | -------- | | array | Array<T> | Yes| Array to which the elements in the container will be copied.| -**Example** - -```ts -let vector = new Vector(); -vector.add(2); -vector.add(4); -vector.add(5); -vector.add(4); -let array = ["a", "b", "c", "d", "e", "f"]; -let result = vector.copyToArray(array); -``` - ### getFirstElement getFirstElement(): T @@ -803,15 +791,15 @@ Obtains 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 | Element obtained.| + | Type| Description| + | -------- | -------- | + | T | Element obtained.| **Example** @@ -840,20 +828,9 @@ Replaces an element at the specified position in this container with a given ele **Return value** -| Type| Description| -| -------- | -------- | -| T | New element.| - -**Example** - - ```ts - let vector = new Vector(); - vector.add(2); - vector.add(4); - vector.add(5); - vector.add(4); - let result = vector.set(2, "A"); - ``` + | Type| Description| + | -------- | -------- | + | T | New element.| ### [Symbol.iterator]