The syntax of List.followedBy() method is:
Iterable<E> followedBy(Iterable<E> other)
This followedBy() method of List creates the lazy concatenation of this iterable and other
.
Parameter | Optional/Required | Description |
---|---|---|
other | required | the iterable to concatenate with this iterable |
List.followedBy() returns value of type Iterable<E>
.
In this example,
numbers1
and numbers2
, containing integers.followedBy()
method on numbers1
to concatenate it with numbers2
.combined
contains elements from both lists in sequence.combined
iterable to standard output.void main() {
var numbers1 = [1, 2, 3];
var numbers2 = [4, 5, 6];
var combined = numbers1.followedBy(numbers2);
print(combined); // Output: (1, 2, 3, 4, 5, 6)
}
(1, 2, 3, 4, 5, 6)
In this example,
letters1
and letters2
, containing characters.followedBy()
method on letters1
to concatenate it with letters2
.combined
contains characters from both lists in sequence.combined
iterable to standard output.void main() {
var letters1 = ['a', 'b', 'c'];
var letters2 = ['x', 'y', 'z'];
var combined = letters1.followedBy(letters2);
print(combined); // Output: (a, b, c, x, y, z)
}
(a, b, c, x, y, z)
In this example,
words1
and words2
, containing strings.followedBy()
method on words1
to concatenate it with words2
.combined
contains strings from both lists in sequence.combined
iterable to standard output.void main() {
var words1 = ['apple', 'banana'];
var words2 = ['cherry', 'date'];
var combined = words1.followedBy(words2);
print(combined); // Output: (apple, banana, cherry, date)
}
(apple, banana, cherry, date)
In this Dart tutorial, we learned about followedBy() method of List: the syntax and few working examples with output and detailed explanation for each example.