# Use primitive arrays in place of Array\<T\>

**URL:** <https://discuss.kotlinlang.org/t/use-primitive-arrays-in-place-of-array-t/25174>\
**Category:** Support\
**Created:** [July 8, 2022, 9:42am UTC](https://discuss.kotlinlang.org/t/use-primitive-arrays-in-place-of-array-t/25174 "2022-07-08T09:42:21Z")\
**Posts on this page:** 3\
**Page:** 2

<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 9, 2022, 8:17pm UTC](https://discuss.kotlinlang.org/t/use-primitive-arrays-in-place-of-array-t/25174/21 "2022-07-09T20:17:08Z")

</div>

Honestly, I think we really talk about the same thing here 😃 I mean a very similar class to yours, but just implementing `List`/`MutableList` instead of `ArrayWrapper`. I don’t see benefits of `ArrayWrapper` and benefits of implementing a list are pretty obvious.

---

<div class="post-metadata">

**Author:** ![Ciel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ciel/32/9351_2.png) [@Ciel](https://discuss.kotlinlang.org/u/Ciel)\
**Post date:** [July 9, 2022, 8:20pm UTC](https://discuss.kotlinlang.org/t/use-primitive-arrays-in-place-of-array-t/25174/22 "2022-07-09T20:20:20Z")

</div>

List is read only  
MutableList has to, by spec, be able to grow in size.  
An array fits neither of their descriptions.

---

<div class="post-metadata">

**Author:** ![gidds](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/gidds/32/10865_2.png) [@gidds](https://discuss.kotlinlang.org/u/gidds)\
**Post date:** [July 12, 2022, 10:06pm UTC](https://discuss.kotlinlang.org/t/use-primitive-arrays-in-place-of-array-t/25174/23 "2022-07-12T22:06:12Z")

</div>

> [@Ciel](#):
>
> MutableList has to, by spec, be able to grow in size.

It doesn’t. Methods that would change the size can instead throw [`UnsupportedOperationException`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unsupported-operation-exception/). That’s exactly what that exception was intended for; and it’s what e.g. Java’s [`Arrays.asList()`](https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList-T...-) does.

Of course, a `MutableList` isn’t a _perfect_ match for a wrapped array. But it could still work.

[Previous page](https://discuss.kotlinlang.org/t/use-primitive-arrays-in-place-of-array-t/25174.md?page=1)
