Collection Conversion
Cangjie allows converting data between different collection types, choosing the type most suitable for each processing step.
Array can initialize an ArrayList by passing the array to the constructor. ArrayList can initialize a HashSet for automatic deduplication. An array of tuples can initialize a HashMap, for example [("key1", val1), ("key2", val2)].
This flexibility lets you use the most appropriate collection type at different stages: use ArrayList during collection to preserve order and duplicates, convert to HashSet for deduplication, and use HashMap for indexed lookups.
The code on the right demonstrates conversions from array to ArrayList, from ArrayList to HashSet (deduplication), and from tuple array to HashMap.
Note
Collection conversion creates a new instance and won't affect the original collection.
HashSet will automatically remove duplicate elements.