# Why Codename One Recommends Avoiding 2D Arrays in Java

DevFeed: [Why Codename One Recommends Avoiding 2D Arrays in Java](<https://devfeed.tech/articles/tip-avoid-2d-arrays-19565.md>)

Original publisher: [Read original article](<https://www.codenameone.com/blog/tip-avoid-2d-arrays/>)

Author: Shai Almog

Published: 2016-12-04T00:00:00Z

Content type: tutorial

Language: en

Sources: [CodeName One](<https://devfeed.tech/sources/codename-one.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>)

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [gc](<https://devfeed.tech/tags/gc.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [java](<https://devfeed.tech/tags/java.md>), [jit](<https://devfeed.tech/tags/jit.md>)

## AI overview

The article explains why Codename One recommends avoiding 2D arrays in Java. It states that multidimensional array semantics create additional arrays, allocations, garbage-collection work, and repeated lookups, especially when processing large image data. It recommends using a one-dimensional array instead, while noting that 2D arrays may be appropriate when row lengths are non-uniform.

## Source excerpt

In the first betas of Codename One we had a lot of bugs related to 2D arrays due to XMLVM. We no longer use XMLVM but the recommendation to avoid 2D arrays remains. We still use them in some occasions e.g. in the creation of a DefaultTableModel but the implementation discards them in favor of an ArrayList internally. __ | To be fair, a 2D array will be faster than an ArrayList so in this case we discarded them due to their lack of