0

This is what I need in pseudocode:

myArray = {
    {Object, Object, Object},
    {Object, Object, Object},
    {Object, Object, Object},
    {Object, Object, Object},
    {Object, Object, Object},
}

How can I declare and initialize something like this in real Java?

1
  • The use of 2-dimensional array is often a symptom of a lack of object design and encapsulation. You should probably use a one-dimensional array (or List, or Set) of Triple instances. A Triple being an object encapsulating your three other objects, and providing useful, high-level methods. Commented Dec 18, 2011 at 7:27

1 Answer 1

3

Just like this...

Object[][] myArray = {
    {obj11, obj12, obj13},
    {obj21, obj22, obj23},
    {obj31, obj32, obj33},
    {obj41, obj42, obj43},
    {obj51, obj52, obj53},
};

Also, see Oracle's array tutorial.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 If myArray is declared separately, you need to change this a little bit to: myArray = new Object[][] { ... };
@TedHopp - indeed, a comment worth mentioning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.