# Mixed Datatype Arrays

**URL:** https://discourse.processing.org/t/mixed-datatype-arrays/14673
**Category:** Beginners
**Created:** [October 13, 2019, 10:32pm UTC](https://discourse.processing.org/t/mixed-datatype-arrays/14673 "2019-10-13T22:32:27Z")
**Posts on this page:** 1
**Showing post:** 5

<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: [October 13, 2019, 11:43pm UTC](https://discourse.processing.org/t/mixed-datatype-arrays/14673/5 "2019-10-13T23:43:05Z")

</div>

> [@KeirMeDear](#):
>
> Is there a way to have various datatypes in one array?

- The only way in pure Java is to go w/ datatype [Object](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html).
- However, in order to read each element from such container, we need to `(cast)` each element back to its actual datatype.
- Which of course is not very practical; and therefore, not recommended.
- The alternative is to create a [`class`](https://processing.org/reference/class.html) containing all the needed datatypes as fields.

```auto
// https://Discourse.Processing.org/t/mixed-datatype-arrays/14673/5
// GoToLoop (2019-Oct-13)

final Mixed[] mix = {
  new Mixed("hello", 1, 2, 3.5), 
  new Mixed("mixed", -1, -2, -3.5), 
  new Mixed("types", MAX_INT, MIN_INT, 1e-3)
};

void setup() {
  printArray(mix);
  exit();
}

class Mixed {
  String txt;
  int a, b;
  float f;

  Mixed(String txt, int a, int b, float f) {
    this.txt = txt;
    this.a = a;
    this.b = b;
    this.f = f;
  }

  String toString() {
    return txt + ", " + a + ", " + b + ", " + f;
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/mixed-datatype-arrays/14673)._
