1# ArkTS Collections 2 3## Overview 4 5The 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 []. 6 7By 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. 8 9ArkTS 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. 10 11Currently, the ArkTS collections contain the following containers: Array, Map, Set, and TypedArray. 12 13For details about how to use the ArkTS containers, see [ArkTS Collections](../reference/apis-arkts/js-apis-arkts-collections.md). 14 15For details about the behavior differences between ArkTS collections APIs and native APIs, see [Behavior Differences](arkts-collections-vs-native-api-comparison.md). 16 17## Example 18 19```ts 20// Index.ets 21import { taskpool } from '@kit.ArkTS'; 22import { SendableTest } from './sendableTest' 23 24@Concurrent 25async function createSendableData(data: SendableTest): Promise<void> { 26 console.info("sendableTest: this is createSendableData"); 27 for(let i = 0;i < 1000;i++) { 28 data.v1.push(i); 29 } 30 data.v2.set(100, "aaa"); 31 data.v3.add("one"); 32 data.v3.add("two"); 33 data.v3.add("three"); 34} 35 36 37async function sendableTask(): Promise<void> { 38 let sendableClass = new SendableTest(); 39 await taskpool.execute(createSendableData, sendableClass); 40 console.info("sendableTest: sendableClass.v1.length is: " + sendableClass.v1.length); 41 console.info("sendableTest: sendableClass.v2.has key is: " + sendableClass.v2.has(100)); 42 console.info("sendableTest: sendableClass.v3.size is: " + sendableClass.v3.size); 43} 44@Entry 45@Component 46struct Index { 47 @State message: string = 'Hello World'; 48 49 build() { 50 Row() { 51 Column() { 52 Button(this.message) 53 .fontSize(50) 54 .fontWeight(FontWeight.Bold) 55 .onClick(async () => { 56 await sendableTask(); 57 }) 58 } 59 .width('100%') 60 } 61 .height('100%') 62 } 63} 64``` 65 66```ts 67// sendableTest.ets 68import { collections } from '@kit.ArkTS'; 69 70@Sendable 71export class SendableTest { 72 v1: collections.Array<number> = new collections.Array<number>(); 73 v2: collections.Map<number, string> = new collections.Map<number, string>(); 74 v3: collections.Set<string> = new collections.Set<string>(); 75 76 constructor() { 77 } 78} 79``` 80