我有两个arraylists
arraylist dName具有值:
mark, 22
peter, 34
ken, 55
arraylist dest有值:
mark, London
peter, Bristol
mark, Cambridge
我想加入合并它们,以便它们的输出给出:
标记
伦敦
剑桥
彼得
布里斯托尔
肯
这是我现在的代码,我真的不是如何分割逗号并搜索其他数组
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 {
}
}
答案 0 :(得分:-1)
你应该迭代数组B.
对于每个字符串,在逗号上拆分并在A中搜索以分割的第一部分开头的字符串。
然后将拆分的第二部分附加到A。
中找到的条目