How do I join two lists in Java?

后端 未结 30 1699
旧巷少年郎
旧巷少年郎 2020-11-22 14:36

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:

30条回答
  •  有刺的猬
    2020-11-22 15:11

    This is simple and just one line, but will add the contents of listTwo to listOne. Do you really need to put the contents in a third list?

    Collections.addAll(listOne, listTwo.toArray());
    

提交回复
热议问题