1e41f4b71Sopenharmony_ci# ArkTS Collections
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThe collections module provides ArkTS containers for efficient data transfer in concurrency scenarios. The ArkTS containers provide similar functionalities as their JavaScript counterparts, except that their properties cannot be added through . or [].
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciBy default, ArkTS containers are passed by reference between concurrent instances. This means that multiple concurrent instances can simultaneously operate the same container instance. Pass-by-copy is also supported. In this mode, each concurrent instance holds an ArkTS container instance.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciArkTS containers are not thread-safe. They adopt the fail-fast approach. An exception is thrown if multiple concurrent instances make structural changes to a container instance at the same time. Therefore, in update scenarios, you must use the ArkTS [asynchronous lock](arkts-async-lock-introduction.md) to ensure secure access to the ArkTS containers.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciCurrently, the ArkTS collections contain the following containers: Array, Map, Set, and TypedArray.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciFor details about how to use the ArkTS containers, see [ArkTS Collections](../reference/apis-arkts/js-apis-arkts-collections.md).
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciFor details about the behavior differences between ArkTS collections APIs and native APIs, see [Behavior Differences](arkts-collections-vs-native-api-comparison.md).
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Example
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci```ts
20e41f4b71Sopenharmony_ci// Index.ets
21e41f4b71Sopenharmony_ciimport { taskpool } from '@kit.ArkTS';
22e41f4b71Sopenharmony_ciimport { SendableTest } from './sendableTest'
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci@Concurrent
25e41f4b71Sopenharmony_ciasync function createSendableData(data: SendableTest): Promise<void> {
26e41f4b71Sopenharmony_ci  console.info("sendableTest: this is createSendableData");
27e41f4b71Sopenharmony_ci  for(let i = 0;i < 1000;i++) {
28e41f4b71Sopenharmony_ci    data.v1.push(i);
29e41f4b71Sopenharmony_ci  }
30e41f4b71Sopenharmony_ci  data.v2.set(100, "aaa");
31e41f4b71Sopenharmony_ci  data.v3.add("one");
32e41f4b71Sopenharmony_ci  data.v3.add("two");
33e41f4b71Sopenharmony_ci  data.v3.add("three");
34e41f4b71Sopenharmony_ci}
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ciasync function sendableTask(): Promise<void> {
38e41f4b71Sopenharmony_ci  let sendableClass = new SendableTest();
39e41f4b71Sopenharmony_ci  await taskpool.execute(createSendableData, sendableClass);
40e41f4b71Sopenharmony_ci  console.info("sendableTest: sendableClass.v1.length is: " + sendableClass.v1.length);
41e41f4b71Sopenharmony_ci  console.info("sendableTest: sendableClass.v2.has key is: " + sendableClass.v2.has(100));
42e41f4b71Sopenharmony_ci  console.info("sendableTest: sendableClass.v3.size is: " + sendableClass.v3.size);
43e41f4b71Sopenharmony_ci}
44e41f4b71Sopenharmony_ci@Entry
45e41f4b71Sopenharmony_ci@Component
46e41f4b71Sopenharmony_cistruct Index {
47e41f4b71Sopenharmony_ci  @State message: string = 'Hello World';
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci  build() {
50e41f4b71Sopenharmony_ci    Row() {
51e41f4b71Sopenharmony_ci      Column() {
52e41f4b71Sopenharmony_ci        Button(this.message)
53e41f4b71Sopenharmony_ci          .fontSize(50)
54e41f4b71Sopenharmony_ci          .fontWeight(FontWeight.Bold)
55e41f4b71Sopenharmony_ci          .onClick(async () => {
56e41f4b71Sopenharmony_ci            await sendableTask();
57e41f4b71Sopenharmony_ci          })
58e41f4b71Sopenharmony_ci      }
59e41f4b71Sopenharmony_ci      .width('100%')
60e41f4b71Sopenharmony_ci    }
61e41f4b71Sopenharmony_ci    .height('100%')
62e41f4b71Sopenharmony_ci  }
63e41f4b71Sopenharmony_ci}
64e41f4b71Sopenharmony_ci```
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci```ts
67e41f4b71Sopenharmony_ci// sendableTest.ets
68e41f4b71Sopenharmony_ciimport { collections } from '@kit.ArkTS';
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci@Sendable
71e41f4b71Sopenharmony_ciexport class SendableTest {
72e41f4b71Sopenharmony_ci  v1: collections.Array<number> = new collections.Array<number>();
73e41f4b71Sopenharmony_ci  v2: collections.Map<number, string> = new collections.Map<number, string>();
74e41f4b71Sopenharmony_ci  v3: collections.Set<string> = new collections.Set<string>();
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci  constructor() {
77e41f4b71Sopenharmony_ci  }
78e41f4b71Sopenharmony_ci}
79e41f4b71Sopenharmony_ci```
80