将 3 个数组列表合并为一个

编程入门 行业动态 更新时间:2024-10-26 12:26:36
本文介绍了将 3 个数组列表合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想在 Java 中将 3 个数组列表合并为一个.有谁知道做这种事情的最好方法是什么?

I want to merge down 3 arraylist in one in java. Does anyone know which is the best way to do such a thing?

推荐答案

使用 ArrayList.addAll().这样的事情应该可以工作(假设列表包含 String 对象;您应该相应地更改).

Use ArrayList.addAll(). Something like this should work (assuming lists contain String objects; you should change accordingly).

List<String> combined = new ArrayList<String>();
combined.addAll(firstArrayList);
combined.addAll(secondArrayList);
combined.addAll(thirdArrayList);

更新

我可以从您的评论中看出您实际上可能正在尝试创建一个 2D 列表.如果是这样,则应使用以下代码:

Update

I can see by your comments that you may actually be trying to create a 2D list. If so, code such as the following should work:

List<List<String>> combined2d = new ArrayList<List<String>>();
combined2d.add(firstArrayList);
combined2d.add(secondArrayList);
combined2d.add(thirdArrayList);

这篇关于将 3 个数组列表合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-16 10:00:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/884909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   并为   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!