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?

3
  • 2
    You're missing an outer pair of curly braces Commented Jan 11, 2014 at 15:10
  • For this, look into maps. Commented Jan 11, 2014 at 15:14
  • 2
    This should probably be a Map<String, Clothing>, where clothing is an interface that captures the contract of your clothing items. Commented Jan 11, 2014 at 15:15

4 Answers 4

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"}};
                  ^         ^         ^
Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

This question looks like a duplicate; you should flag to close instead of posting the link as an answer
0
Object data[][] = 
{
    {"Item#1", jackets.getDescription(), //... },
    {"Item#2", designerJeans.getDescription(), //...}
};

Comments

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)}};

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.