You can go on with the following approach.
String yourString="2\n1,3,5\n2,5\n3,4,2\n5"; //Added newline characters for each newline
String lines[]=yourString.split("\n");
int roomLayout[][]=new int[lines.length][];
// for each line, split them and store them in your 2d array
for(int i=0;i<lines.length;i++){
String parts[]=lines[i].split(",");
int[] numbers=new int[parts.length];
for(int j=0;j<parts.length;j++){
numbers[j]=Integer.parseInt(parts[j]);
}
// assign your row as a row in the roomLayout.
roomLayout[i]=numbers;
}
// Whenever you access the array, that is i'th room (indexed from 0)
// access allowed rooms as
for(int x=0;x<rooLayout[i].length;x++){
System.out.println(roomLayout[i][x]);
}
Otherwise you can go with ArrayLists, which is a good alternative in your situation.
roomLayoutassignment can be done likeroomLayout[0][0] = 2;numberOfRoomscome from?