I am trying to figure out why I could not define the 2d Array in the asList() method like you might a normal Array.
We cannot answer why what you tried did not work when you do not tell us what you tried. I suppose what you really want to know, however, is how to generate a List<String[]>
via Arrays.asList()
by passing the individual elements, instead of first constructing a 2D array. That would be this:
public final List<String[]> pockets = Arrays.asList(
new String[]{"STATUS CHANGERS", "RUNES", "KEY ITEMS", "TROPHIES"},
new String[]{"POTION", "SUPER POTION", "FULL HEAL"},
new String[]{"ARMOR+","ATTACK+","EXP+","HEALTH+", "DISPELL+"},
new String[]{"QUEST ITEMS","STORY ITEMS","JOURNAL"},
new String[]{"TROPHIES"}
);
Note in particular that Java has no array literals, only array initializers (which can be associated with array declarations), and array constructors, such as in the above code. I speculate that in your attempt(s), you omitted the new String[]
bits that make those constructors. Those bits are necessary to specify the element type of the arrays, if for no other reason.
Also, I know there has to be a Java subclass to import or a more semantic approach.
I've no idea what you mean. You're already using class java.util.Array
to perform the construction, and you're building a java.util.List
. I guess for most purposes I'd recommend using a List
of List
s (List<List<String>>
) and avoiding arrays altogether, but I can't be sure whether that would be suitable for your purposes.