0

I'm not sure whether this is even possible or not... I'm only starting to program in Java.

So my question is. I created this multidimensional array which contains objects.

Could you please check it and see what am I doing wrong?

Object data[][] = 
{"Item#1", jackets.getDescription(), jackets.getUnitOnHand(), jackets.getPrice(0) }
{"Item#2", designerJeans.getDescription(), designerJeans.getUnitOnHand(), designerJeans.getPrice(0)};

Could you tell me whats wrong in the above code?

John Dvorak
  • 26,799
  • 13
  • 69
  • 83
TSlegaitis
  • 1,231
  • 15
  • 29

4 Answers4

1

You need to use another more { and } and also have to use a comma in between like {}, {}

For example:

Object data[][] = {{"2","3"},{"1","2"}};
                  ^         ^         ^
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
0
int[][][] threeDimArr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } };

(Initialising a multidimensional array in Java)

So obviously you have to add outer brackets.

Community
  • 1
  • 1
0
Object data[][] = 
{
    {"Item#1", jackets.getDescription(), //... },
    {"Item#2", designerJeans.getDescription(), //...}
};
Merlin
  • 4,907
  • 2
  • 33
  • 51
0

You need to encapsulate the sub arrays into the array:

Object data[][] = {{"Item#1", jackets.getDescription(), jackets.getUnitOnHand(), jackets.getPrice(0)},
    {"Item#2", designerJeans.getDescription(), designerJeans.getUnitOnHand(), designerJeans.getPrice(0)}};
Ned
  • 179
  • 1
  • 6