Is this matrice definition correct in java?

mehdi :

i was following this code example and i'm new to java but this array definition seems confusing to me this is the link : https://www.codejava.net/coding/how-to-write-excel-files-in-java-using-apache-poi

array of type objects

dan1st :

Let's simplify it to that:

Object[][] data={
    {"A0","B0",0},
    {"A1","B1",1}
}

Object[] a={<content>} is a short form of Object[] a=new Object[]{<content>} but this does only work in the declaration.

It does not work like this:

Object[] data;
data={};

but the following will work:

Object[] data={};

Object[][] means an array of array of objects.

The outer array contains of two(in your case four) arrays: {"A0","B0",0}, and {"A1","B1",1},.

Each inner array consists of 3 objects.

As a String is an Object and the numbers are automatically boxed to objects, the inner arrays can easily be created as arrays of objects.

Note that the inner arrays can have different lengths because Object[][] just requires arrays of objects and the length does not matter for that.

Also note that every type (in java) implicitely extends object and you can therefor store everything in an Object.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=14007&siteId=1