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?
asked Dec 18, 2011 at 6:42
Conner Ruhl
1,7235 gold badges20 silver badges32 bronze badges
-
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.JB Nizet– JB Nizet2011年12月18日 07:27:04 +00:00Commented Dec 18, 2011 at 7:27
1 Answer 1
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.
answered Dec 18, 2011 at 6:44
MByD
138k30 gold badges269 silver badges278 bronze badges
lang-java