How do I combine two lists in Dart?

前端 未结 8 774
有刺的猬
有刺的猬 2021-01-31 00:46

I was wondering if there was an easy way to concatenate two lists in dart to create a brand new list object. I couldn\'t find anything and something like this:

My list:

8条回答
  •  广开言路
    2021-01-31 01:40

    We can add all the elements of the other list to the existing list by the use of addAll() method.

    Using addAll() method to add all the elements of another list to the existing list. and Appends all objects of iterable to the end of this list.

    Extends the length of the list by the number of objects in iterable. Throws an UnsupportedError if this list is fixed-length.

    Creating lists

    listone = [1,2,3]
    listtwo = [4,5,6]
    

    Combining lists

     listone.addAll(listtwo);
    

    Output:

    [1,2,3,4,5,6]
    

提交回复
热议问题