chevron-up bell reply instagram twitter2 feed3 finder search-25px-p0

A comparison between Kotlin and Swift: Collections


Similar to Swift, collection in Kotlin includes:

  • List
  • Set
  • Map

1. List

Features of List:

  • May have duplicate element
  • May hold different data types
  • All elements are unordered

Similar to array in swift, list can be immutable and mutable. With immutable list, it can't be added or removed.

In Swift, the mutable and immutable array is differentiated by using let and var. For example:

2. Set

  • Must have NO duplicate
  • May hold different data types
  • Unordered

Swift version:

3. Map

Equivalent to dictionary

  • Key-Value pair
  • No duplicate

Swift version: