我有兩個的ArrayList合併兩個數組列表
ArrayList中DNAME有值:
mark, 22
peter, 34
ken, 55
ArrayList中DEST有值:
mark, London
peter, Bristol
mark, Cambridge
我想加入合併他們,使他們輸出給出:
馬克
倫敦
劍橋
彼得
布裏斯托爾
肯
這是代碼我有現在的我,不重新盟友usre如何分割的逗號和搜索其他陣列
public class Sample {
BufferedReader br;
BufferedReader br2;
public Sample() {
ArrayList<String> dName = new ArrayList<String>();
ArrayList<String> dest = new ArrayList<String>();
String line = null;
String lines = null;
try {
br = new BufferedReader(new FileReader("taxi_details.txt"));
br2 = new BufferedReader(new FileReader("2017_journeys.txt"));
while ((line = br.readLine()) != null &&
(lines = br2.readLine()) != null){
String name [] = line.split(";");
String destination [] = lines.split(",");
// add values to ArrayList
dName.add(line);
dest.add(lines);
// iterate through destination
for (String str : destination) {
}
}
}
catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (br != null)
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) throws IOException {
}
}
你把它稱爲一個「ArrayList中,」所以我猜這是Java,但你真的應該標記您正在使用什麼語言。另外,我建議看看如何使用markdown格式化您的問題。 Stackoverflow給你一些提示和預覽。很難確切地說出你在問什麼。你能發佈你的代碼嗎?最後,你有Google嗎? – TheCrzyMan
謝謝。是的,我已經嘗試谷歌,但我沒有得到我想要的。很多人都會用錯誤的語言? – diamondgirl
輸出是否爲[[「mark,London,Cambridge」,「peter,Bristol」,「Ken」]''。或者,我想更準確地說,你處理的是什麼類型?字符串?同樣,我會建議看看數據結構「地圖」。這聽起來像它可以幫助你在這裏 – TheCrzyMan