THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This tutorial shows how to check sublist exists in Dart or Flutter List
dart list provides multiple ways to check the sub list contains in the list of elements.
First Convert list into set using Set.of()
method
Check sub list exists in Set using Set.containsAll()
method
Here is an example code
void main() {
var list = [1, 4, 5, 2, 8];
var sublist = [1, 4];
var set = Set.of(list);
print(set.containsAll(sublist)); //true
print(set.containsAll([2, 3])); //false
}
Check isEmpty() returns true if list is empty
import 'package:enumerable/enumerable.dart';
void main() {
var list = [1, 4, 5, 2, 8];
var sublist = [1, 4];
print(sublist.except(list).isEmpty); //true
print([2, 3].except(list).isEmpty); //false
}
To summarize, Learn how to check the sublist contains all elements in a list dart and flutter.
🧮 Tags
Recent posts
Multiple ways to iterate a loop with index and element in array in swift How to reload a page/component in Angular? How to populate enum object data in a dropdown in angular| Angular material dropdown example How to get the current date and time in local and UTC in Rust example Angular 13 UpperCase pipe tutorial | How to Convert a String to Uppercase exampleRelated posts