Hey guys sorry i'm a noob at java but im trying to make something and i need a multidimensional array list. It must be implemented into the following code:
public static void OpenFile() {
ArrayList<ArrayList<String>> array = new ArrayList<ArrayList<String>>();
int retrival = chooser.showOpenDialog(null);
if (retrival == JFileChooser.APPROVE_OPTION) {
try (BufferedReader br = new BufferedReader(new FileReader(
chooser.getSelectedFile()))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
if (sCurrentLine.equals("")) {
continue;
} else if (sCurrentLine.startsWith("Question")) {
System.out.println(sCurrentLine.split(":")[1]);
//add to [0] in array ArrayList
} else if (sCurrentLine.startsWith("Answer")) {
System.out.println(sCurrentLine.split(":")[1]);
//add to [1] in array ArrayList
} else if (sCurrentLine.startsWith("Category")) {
System.out.println(sCurrentLine.split(":")[1]);
//add to [2] in array ArrayList
} else if (sCurrentLine.startsWith("Essay")) {
System.out.println(sCurrentLine.split(":")[1]);
//add to [3] in array ArrayList
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
All the [1] index's of the strings i split need to go into a multidimesional array in this order: question, answer, category, essay.
So i am currently using a normal multidimensional array but you cant change the values of it easily. What i want my multidimensional arraylist to look like is this:
MultiDimensional ArrayList
- [0]: questions(it may be over 100 of them.)
- [1] answers(it may be over 100 of them.)
- [2] category(it may be over 100 of them.)
- [3] essay(it may be over 100 of them.)