> 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.
Similar to **ArrayList**, **[Vector](js-apis-vector.md)** is also implemented based on arrays and can dynamically adjust the capacity. It increases the capability by 100% each time.
...
...
@@ -14,6 +11,11 @@ When compared with **[LinkedList](js-apis-linkedlist.md)**, **ArrayList** is mor
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
...
...
@@ -160,9 +162,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
> 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.
Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted order, **HashSet** stores data in a random order. This means that **HashSet** may use a different order when storing and accessing elements. Both of them allows only unique elements. However, null values are allowed in **HashSet**, but not allowed in **TreeSet**.
...
...
@@ -12,6 +9,11 @@ Unlike [TreeSet](js-apis-treeset.md), which stores and accesses data in sorted o
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
...
...
@@ -125,9 +127,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
> 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. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
...
...
@@ -17,6 +14,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
...
...
@@ -197,9 +199,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
> 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.
**LightWeightSet** is based on generics and uses a lightweight structure. Its default initial capacity is 8, and it has the capacity doubled in each expansion.
...
...
@@ -16,6 +13,11 @@ Compared with **[HashSet](js-apis-hashset.md)**, which can also store values, **
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
...
...
@@ -227,9 +229,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
letlightWeightSet=newLightWeightSet();
letresult=lightWeightSet.has(123);
lightWeightSet.add(123);
result=lightWeightSet.has(123);
letresult=lightWeightSet.has(123);
```
...
...
@@ -267,7 +268,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
@@ -13,6 +13,7 @@ This topic uses the following to identify the use of generics:
>
> 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
...
...
@@ -160,9 +161,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
> 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.
**PlainArray** is based on generics and uses a lightweight structure. Keys in the array are searched using binary search and are mapped to values in other arrays.
...
...
@@ -14,6 +11,11 @@ Both **PlainArray** and **[LightWeightMap](js-apis-lightweightmap.md)** are used
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
...
...
@@ -21,7 +23,6 @@ import PlainArray from '@ohos.util.PlainArray';
```
## PlainArray
### Attributes
...
...
@@ -118,9 +119,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
> 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.
Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at both the ends, **Queue** supports insertion at one end and removal at the other end.
...
...
@@ -12,6 +9,11 @@ Unlike **[Deque](js-apis-deque.md)**, which supports insertion and removal at bo
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 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.
Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue data structure and supports insertion at one end and removal at the other end, **Stack** supports insertion and removal at the same end.
...
...
@@ -12,6 +9,11 @@ Unlike **[Queue](js-apis-queue.md)**, which is implemented based on the queue da
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.
@@ -18,6 +18,7 @@ This topic uses the following to identify the use of generics:
>
> 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
...
...
@@ -126,9 +127,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
lettreeMap=newTreeMap();
letresult=treeMap.hasKey("squirrel");
treeMap.set("squirrel",123);
letresult1=treeMap.hasKey("squirrel");
letresult=treeMap.hasKey("squirrel");
```
...
...
@@ -164,9 +164,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
```ts
lettreeMap=newTreeMap();
letresult=treeMap.hasValue(123);
treeMap.set("squirrel",123);
letresult1=treeMap.hasValue(123);
letresult=treeMap.hasValue(123);
```
...
...
@@ -304,7 +303,7 @@ let map = new TreeMap();
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
console.log("value"+value,"key"+key);// Print result: 12 demo, 356 sparrow, and 123 squirrel
})
```
...
...
@@ -380,7 +379,7 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
@@ -14,6 +14,7 @@ This topic uses the following to identify the use of generics:
>
> 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
...
...
@@ -122,9 +123,8 @@ For details about the error codes, see [Utils Error Codes](../errorcodes/errorco
The **util** module provides common utility functions, such as **TextEncoder** and **TextDecoder** for string encoding and decoding, **RationalNumber** for rational number operations, **LruBuffer** for buffer management, **Scope** for range determination, **Base64** for Base64 encoding and decoding, and **Types** for checks of built-in object types.
The **util** module provides common utility functions, such as [TextEncoder](#textencoder) and [TextDecoder](#textdecoder) for string encoding and decoding, [RationalNumber<sup>8+</sup>](#rationalnumber8) for rational number operations, [LRUCache<sup>9+</sup>](#lrucache9) for cache management, [ScopeHelper<sup>9+</sup>](#scopehelper9) for range determination, [Base64Helper<sup>9+</sup>](#base64helper9) for Base64 encoding and decoding, and [types<sup>8+</sup>](#types8) for built-in object type check.
> **NOTE**
>
...
...
@@ -337,6 +337,8 @@ Processes an asynchronous function and returns a promise.
## TextDecoder
Provides APIs to decode byte arrays into strings. It supports multiple formats, including UTF-8, UTF-16LE, UTF-16BE, ISO-8859, and Windows-1251.
| ignoreBOM | boolean | No| Whether to ignore the BOM.|
| fatal | boolean | No| Whether to display fatal errors. The default value is **false**.|
| ignoreBOM | boolean | No| Whether to ignore the BOM. The default value is **false**.|
**Example**
...
...
@@ -508,13 +510,15 @@ Decodes the input content.
## TextEncoder
Provides APIs to encode strings into byte arrays. It supports multiple formats, including UTF-8, UTF-16LE, and UTF-16BE. When **TextEncoder** is used for encoding, the number of bytes occupied by a character varies according to the encoding format. For example, a Chinese character usually occupies three bytes in UTF-8 encoding format but two bytes in UTF-16LE or UTF-16BE encoding format. Therefore, when using **TextEncoder**, you must explicitly specify the encoding format to obtain the required encoding result.
| encoding | string | Yes| No| Encoding format. The default format is **utf-8**.|
| encoding | string | Yes| No| Encoding format. The default format is **'utf-8'**.|
### constructor
...
...
@@ -679,6 +683,8 @@ Encodes the input content.
## RationalNumber<sup>8+</sup>
Provides APIs to compare rational numbers and obtain numerators and denominators. For example, the **toString()** API can be used to convert a rational number into a strings.
### constructor<sup>9+</sup>
constructor()
...
...
@@ -1063,6 +1069,8 @@ let result = util.RationalNumber.getCommonDivisor(4,6);
## LRUCache<sup>9+</sup>
Provides APIs to discard the least recently used data to make rooms for new elements when the cache is full. This class uses the Least Recently Used (LRU) algorithm, which believes that the recently used data may be accessed again in the near future and the least accessed data is the least valuable data and should be removed from the cache.
@@ -2023,6 +2033,8 @@ let result = range.clamp(tempMiDF);
## Base64Helper<sup>9+</sup>
The Base64 encoding table contains 62 characters, which are the uppercase letters (A-Z), lowercase letters (a-z), digits (0-9), and the special characters plus sign (+) and slash (/). During encoding, the original data is divided into groups of three bytes, and each group contains a 6-bit number. Then, the corresponding characters in the Base64 encoding table are used to represent these numbers. If the last group contains only one or two bytes, the equal sign (=) is used for padding.
Provides APIs to check different types of built-in objects, such as ArrayBuffer, Map, and Set, so as to avoid exceptions or crashes caused by type errors.