0

I'm trying to create a class that holds a 2D string array to be used by another class. For some reason, my IDE gives me a bunch of errors when I try to compile. Here's my code:

public class Lists {
    String[][] ListArrays = {"Why, Hello there!","Welcome.","blah blah blah","more useless crap", null},
    {"This is where List 1 will go"}, {"This is where List 2 will go"}, {"This is where List 3 will go"}, 
    {"This is where List 4 will go"}, {"This is where List 5 will go"}, {"This is where List 6 will go"},
    {"This is where List 7 will go"}, {"This is where List 8 will go"}, {"This is where List 9 will go"},
    {"This is where List 10 will go"};
}

The errors I'm getting are: <identifier> expected, illegal start of type, and ';' expected.
I've had issues with multidimensional arrays before, but I'm not sure why. Any help would be appreciated.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by nocookies92
0

You need another set of curly braces surrounding the whole mess.
Like so:

public class Lists {
	static	String[][] la = {{"a", "n", "s"}, {"1","2","3"}};

	public static void main (String[]args)
	{
		for (String[] sa:la)
			for (String s:sa)
				System.out.println(s);
	}
}
0

Yeah, I realized I made that mistake right as I went to be last night. Sorry to ask such a stupid question.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.