我需要幫助將數據從4 ArrayLists
傳輸到多維數組。請查看我的變量中的註釋。將數據從多個數組列表轉換爲多維數組
我需要把從所有的ArrayList數據到card[][]
格式爲:
card[][] = {{questions,answers,category,essay}};
代碼:
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser;
public class Test {
static JFileChooser chooser = new JFileChooser();
//these need to go into card[][]
static List<String> questions = new ArrayList<String>();
static List<String> answers = new ArrayList<String>();
static List<String> categories = new ArrayList<String>();
static List<String> essays = new ArrayList<String>();
static String[][] card;
public static void main(String[] args) {
OpenFile();
}
public static void OpenFile() {
int retrival = chooser.showOpenDialog(null);
if (retrival == JFileChooser.APPROVE_OPTION) {
String line;
try (BufferedReader br = new BufferedReader(new FileReader(
chooser.getSelectedFile()))) {
while ((line = br.readLine()) != null) {
String[] splitted = line.split("Question: ");
String[] splittedAnswer = line.split("Answer: ");
String[] splittedCategory = line.split("Category: ");
String[] splittedEssay = line
.split("Essay Question Possibility: ");
if (splittedAnswer.length == 2) {
answers.add(splittedAnswer[1]);
} else if (splitted.length == 2) {
questions.add(splitted[1]);
} else if (splittedCategory.length == 2) {
categories.add(splittedCategory[1]);
} else if (splittedEssay.length == 2) {
essays.add(splittedEssay[1]);
}
}
br.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
哇......你想在這裏完成什麼?爲什麼你不能僅僅使用一些簡單的東西,比如一個包含問題,答案,類別,散文的類的數組列表? – futureelite7