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.

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.