java如何通过追加连接两个列表
我试过:
List splice(List l1, List l2){
List l3 = new LinkedList();
return l3;
}
List append(List l1, List l2) {
List to_return = copy(l1);
List l3 = copy(l2);
while (true) {
if (l3.isEmpty())
return to_return;
to_return = append1(to_return,hd(l3));
l3 = tl(l3);
}
}
接下来我该怎么办?如果我输入[1,2,3]
和[a,b]
,我想得到[1,a,2,b,3]
# 1 楼答案
我不太懂你的代码,但你说
这可以通过以下方式实现:
编辑
根据您使用的
List
实现,本文中接受答案的方法可能更有效:Java: Interleave two integer based arraylists -> good approach?