gpt4 book ai didi

java - 如何按索引顺序将两个arraylist合并为一个arraylist

转载 作者:太空狗 更新时间:2023-10-29 14:00:19 26 4
gpt4 key购买 nike

<分区>

I have two array lists that hold x amount of equal elements, the idea is to combine both arraylists into one, but I want to add element by element in index order, currently I have this code listed below, but its not very efficient:

ArrayList <String> listA = ["a", "c", "e"]
ArrayList <String> listB = ["b", "d","f"]
ArrayList <String> listC;
for (int i = 0; i < listA.size() + listB.size(); i++){
listC.add(listA.get(i));
lictC.add(listB.get(i));
}
return listC;

output = ["a", "b", "c", "d", "e", "f"];

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com