.addAll()
Published May 13, 2024
Contribute to Docs
In Dart, the .addAll()
method adds all collection elements to the end of a queue. This method is part of the Queue
class in the dart:collection
library. It is useful for merging two collections where the order of the elements is preserved and duplicates are not removed.
Syntax
queue.addAll(collection)
queue
: The instance of aQueue
where elements will be added.collection
: The collection of elements to add to the queue. This can be of any class implementing theIterable
interface.
Note: The
.addAll()
method does not return a value.
Example
In the following example, the .addAll()
method takes all elements from the moreNumbers
list and adds them to the end of the numbers
queue:
import 'dart:collection';void main() {Queue<int> numbers = Queue.from([1, 2, 3]);List<int> moreNumbers = [4, 3, 5, 6];print(numbers);numbers.addAll(moreNumbers);print(numbers);}
The output for the above code is:
{1, 2, 3}{1, 2, 3, 4, 3, 5, 6}
Note: Since the
Queue
class is part of thedart:collection
library, the library must be imported into the code to makeQueue
work as intended.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.