I am trying to instantiate a 2 dimensional array of strings. My issues is that the 2nd dimensions of the array are not all the same and I am not sure how to specify this code wise.
These variable specify electrical boards. There are 4 boards, each with a varying number of contacts. For each contact there is a description about its purpose.
int numBoards = 4;
String[] boardNames = {"FirstBoard", "Second Board", "Third Board", "Fourth Board"};
int[] numContacts = { 32, 24, 48, 32 };
String[][] descriptions = new String[numBoards][???];
How can I specify that my 2nd dimensions of the descriptions array are of varying sizes; the sizes specified in numContacts?
Is this the only way to do it? Or is there something more elegant?
int numBoards = 4;
String[] boardNames = {"FirstBoard", "Second Board", "Third Board", "Fourth Board"};
int[] numContacts = { 32, 24, 48, 32 };
String[] desc1 = new String[numContacts[0]];
String[] desc2 = new String[numContacts[1]];
String[] desc3 = new String[numContacts[2]];
String[] desc4 = new String[numContacts[3]];
String[][] descriptions = new String[numBoards][];
descriptions[0] = desc1;
descriptions[1] = desc2;
descriptions[2] = desc3;
descriptions[3] = desc4;