# Concat with an object not working

**URL:** https://discourse.processing.org/t/concat-with-an-object-not-working/20632
**Category:** Beginners
**Created:** [May 8, 2020, 4:18pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632 "2020-05-08T16:18:03Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 8, 2020, 4:32pm UTC](https://discourse.processing.org/t/concat-with-an-object-not-working/20632/2 "2020-05-08T16:32:52Z")

</div>

> [@Eyetoof](#):
>
> … where **concat()** is not happy.

> **[concat() / Reference](https://processing.org/reference/concat_.html)**
>
> Concatenates two arrays. For example, concatenating the array { 1, 2, 3 } and the array { 4, 5, 6 } yields { 1, 2, 3, 4, 5, 6 }. Both parameters must be arrays of the same datatype. When u…

> When using an array of objects, the data returned from the function must be cast to the object array’s data type.  
> For example: `SomeClass[] items = (SomeClass[]) concat(array1, array2);`.

If you dislike using the `(cast)` operator for **concat()** I can write for you a version that doesn’t need it like I did for [**append()**](https://processing.org/reference/append_.html):

> [@Unable to append to an array of G4P objects](https://discourse.processing.org/t/unable-to-append-to-an-array-of-g4p-objects/19898/7):
>
> Using (cast) is indeed not ideal. If you wish, you can override append() pasting the 3 methods below on your sketch, so (cast) isn’t needed anymore: wink static final \<T\> T[] expand(final T[] list) { return expand(list, list.length \<\< 1); } static final \<T\> T[] expand(final T[] list, final int newSize) { return java.util.Arrays.copyOf(list, newSize); } static final \<T\> T[] append(final T[] list, final T value) { final T[] arr = expand(list, list.length + 1); arr[arr.length - 1] = va…

---

_[View the full topic](https://discourse.processing.org/t/concat-with-an-object-not-working/20632)._
