- 创建一个新的 List,其中包含交错的 list1 的元素
- 与list2的元素。例如,如果 list1 成立
- <"over","river","through","woods"> 和 list2 包含 <"the","and","the">,
- 那么新列表应该保持
- <"over","the","river","and","through","the","woods">。交替
- 清单 1 和清单 2。如果一个列表较长,则新列表将包含所有
- 最后较长列表中的额外值。例如,如果 list1
- 持有 <"over","river","through","woods"> 和 list2 持有 <"the","and">
- 那么新列表应该保持
- <"over","the","river","and","through","woods">。
我编程很烂,看不到这个作业最后一部分的逻辑。感谢您花时间看这个。//*
private static List<String> mergeLists(List<String> list1, List<String> list2) {
long max = Math.max(((File) list1).length(),((File) list2).length());
ArrayList<String> newlist = new ArrayList<String>();
for (int i = 0; i < max; i++) {
if (i < list1) {
newlist.append(list1[i]);
{
if (i < list2) {
newlist.append(list2[i]);
}
}
return newlist;
}
}
}