How to concat two ArrayLists?

后端 未结 7 1305
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 23:29

I have two ArrayLists of equal size. List 1 consists of 10 names and list 2 consists of their phone numbers.

I want to concat the names and number into

7条回答
  •  醉话见心
    2020-12-14 00:15

    If you want to do it one line and you do not want to change list1 or list2 you can do it using stream

    List list1 = Arrays.asList("London", "Paris");
    List list2 = Arrays.asList("Moscow", "Tver");
    
    List list = Stream.concat(list1.stream(),list2.stream()).collect(Collectors.toList());
    

提交回复
热议问题