如何在Java中加入两个列表? [英] How do I join two lists in Java?

查看:138
本文介绍了如何在Java中加入两个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

条件:不修改原始列表;仅限JDK,没有外部库。单行或JDK 1.3版本的奖励积分。

Conditions: do not modifiy the original lists; JDK only, no external libraries. Bonus points for a one-liner or a JDK 1.3 version.

是否有比以下更简单的方法:

Is there a simpler way than:

List<String> newList = new ArrayList<String>();
newList.addAll(listOne);
newList.addAll(listTwo);


推荐答案

在我的头顶,我可以缩短它一行:

Off the top of my head, I can shorten it by one line:

List<String> newList = new ArrayList<String>(listOne);
newList.addAll(listTwo);

这篇关于如何在Java中加入两个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆