# Create array as \[1, 2, 3\] and maps as { a: 10 }

**URL:** <https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506>\
**Category:** Uncategorized\
**Created:** [July 24, 2021, 3:17pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506 "2021-07-24T15:17:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex22](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alex22/32/7822_2.png) [@alex22](https://discuss.kotlinlang.org/u/alex22)\
**Post date:** [July 24, 2021, 3:17pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/1 "2021-07-24T15:17:09Z")

</div>

Just wondering if there’re any plans to introduce a human way to create collections? Something like `[1, 2, 3]` and maps as `{ a: 10 }`.

I believe the reason they weren’t introduced originally, because it was not clear how to do it in a proper way.

Kotlin development started 11 years ago, in 2010. How many more years kotlin dev team needs to solve this immensely complicated challenge?

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [July 24, 2021, 3:25pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/2 "2021-07-24T15:25:24Z")

</div>

It is called collection literals, and you should probably watch [this video](https://www.youtube.com/watch?v=MBKxQcAxLhk) for discussion.

Personally, I do not see how `[1,2,3]` is be better than `List(1,2,3)`. When I just started to work in kotlin (after groovy), I was advocating for collection literals, but after four years, I changed my perspective and now I do not see any viable reasons to introduce them.

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [July 24, 2021, 3:31pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/3 "2021-07-24T15:31:44Z")

</div>

By saying `[1, 2, 3]` which one do you mean exactly?

```
listOf(1, 2, 3)
mutableListOf(1, 2, 3)
arrayOf(1, 2, 3)
arrayListOf(1, 2, 3)

```

I think current solution is better, because it is explicit what kind of data structure we need to create.

---

<div class="post-metadata">

**Author:** ![alex22](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alex22/32/7822_2.png) [@alex22](https://discuss.kotlinlang.org/u/alex22)\
**Post date:** [July 24, 2021, 3:43pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/4 "2021-07-24T15:43:59Z")

</div>

> By saying `[1, 2, 3]` which one do you mean exactly?

Possible solutions could be

1. infer type `val list: List<Int> = [1, 2, 3]`
2. For `val list = [1, 2]` collect usage stats over top 100 kotlin projects on github and see what’s used the most frequently. If you want something else do `val list = [1, 2, 3].toMutableList()` or use old way `val list = mutableListOf(1, 2, 3)`.

The thing is - you lose nothing, if you wish you can just ignore this literal syntax and continue to use `whateverOf(1, 2, 3)`. But people who like this syntax could use it.

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [July 24, 2021, 3:47pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/5 "2021-07-24T15:47:45Z")

</div>

My personal opinion is that the current solution is better than both of your suggestions. But as I said, this is just an opinion.

Anyway, the case here is not that this feature is missing, but it was designed in a different way than you expect.

---

<div class="post-metadata">

**Author:** ![broot](https://avatars.discourse-cdn.com/v4/letter/b/a88e57/32.png) [@broot](https://discuss.kotlinlang.org/u/broot)\
**Post date:** [July 24, 2021, 5:23pm UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/6 "2021-07-24T17:23:04Z")

</div>

Also, it seems this is actually planned for future versions of Kotlin. It is/was discussed [here](https://github.com/Kotlin/KEEP/pull/112) and [here](https://youtrack.jetbrains.com/issue/KT-43871). It takes years already for arguing on what would be the best design for this proposal 😉

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [July 25, 2021, 7:37am UTC](https://discuss.kotlinlang.org/t/create-array-as-1-2-3-and-maps-as-a-10/22506/7 "2021-07-25T07:37:42Z")

</div>

The current collection literal proposal makes sense in conjunction with the tuple builders proposal, but not as a stand-alone feature.
