# Having a problem with zero length arrays

**URL:** https://discourse.processing.org/t/having-a-problem-with-zero-length-arrays/45555
**Category:** Coding Questions
**Tags:** homework
**Created:** [January 8, 2025, 5:45am UTC](https://discourse.processing.org/t/having-a-problem-with-zero-length-arrays/45555 "2025-01-08T05:45:03Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 9, 2025, 10:18am UTC](https://discourse.processing.org/t/having-a-problem-with-zero-length-arrays/45555/5 "2025-01-09T10:18:03Z")

</div>

Welcome to the forum when you paste code it is best to [format your code](https://discourse.processing.org/t/guidelines-asking-questions/2147#is-your-post-formatted-9) to make it easier for others to read. You can edit your last post to format the code rather than re-post.

> [@tajvirsingh](#):
>
> I am trying develop this code to render 3D objects.

I see in the code you have specified the details of a 3D cube so are you planning to render

1. simple 3D geometric shapes e.g. cuboids, ellipsoids, cones, tubes etc, or
2. complex 3D models e.g. those used in games etc.

If the first option do you

1. want to create the source code from scratch, or
2. are you prepared to use a contributed library to do the hard work.

If the later then I can recommend a truly excellent library, Shapes3D it comes with good examples and supporting [website](http://www.lagers.org.uk/s3d4p/index.html). It can even be installed in the PDE using the contributions manager 😁 Sorry about the plug but as the library creator I am a little biased. 😇

If the former then I suggest you use PVector and PMatrix3D to represent and manipulate 3D coordinates rather than 2D arrays directly.

Creating and manipulating 2D arrays in Java is mind bending stuff. In the code below two arrays are declared and defined , `a` and `b` , they look similar but produce orthogonal arrays

```auto
float a[][] = new float[1][4];
float b[][] = {{0}, {0}, {0}, {0}};

void setup() {
  a[0][3] = 3.142;
  b[3][0] = 2.728;
  a2dPrint("Array 'a'", a); 
  a2dPrint("Array 'b'", b); 
}

void a2dPrint(String title, float[][] array) {
  println("######", title, "#####");
  println(" Size", array.length, "x", array[0].length);
  for (int i = 0; i < array.length; i++) {
    print(" ");
    for (int j = 0; j < array[i].length; j++) {
      print(array[i][j], " ");
    }
    println();
  }
  println("---------------------------------------");
}

```

Output:

```auto
###### Array 'a' #####
   Size 1 x 4
    0.0 0.0 0.0 3.142   
---------------------------------------
###### Array 'b' #####
   Size 4 x 1
    0.0   
    0.0   
    0.0   
    3.142   
---------------------------------------

```

---

_[View the full topic](https://discourse.processing.org/t/having-a-problem-with-zero-length-arrays/45555)._
