List

  var fruits = ['apples'.'oranges'];
  fruits.add('kiwis');
  fruits.addAll(['grapes'.'bananas']);
  
  // indexOf finds the position of the element and returns the index
  var appleIndex = fruits.indexOf('apples');
  print(appleIndex); / / 0
  
  // removeAt removes elements by index
  fruits.removeAt(appleIndex);
  print(fruits); // [oranges, kiwis, grapes, bananas]
  
  // contains Contains an element
  print(students.contains('bananas')); // true
  
  // clear clears the array
  fruits.clear();
  
  // isEmpty checks whether the array isEmpty
  print(fruits.isEmpty); // true

  // Fill an array of known length with a specific element
  var vegetables = List.filled(3.'broccoli');
  print(vegetables); // [broccoli, broccoli, broccoli]
  
  Use every() to determine if every element in the array satisfies the specified condition
  print(vegetables.every((v) => v == 'broccoli'));
  
  List numbers = [2.8.4.6.7.3];
  
  // any returns true as long as one condition satisfies the condition
  print(numbers.any((element) => element == 8)); // true
  
  // reduce adds each value in the array to the previously returned value and returns the sum
  print(numbers.reduce((value, element) => value + element)); / / 30
  
  // Fold () is used in much the same way as reduce(), except that it provides an initial value
  print(numbers.fold(10, (value, element) => (value as int) + element)); / / 40
  
  // forEach traverses the number group
  numbers.forEach((element) => print(element));
  
  // Map can be used to manipulate each item in a given array and return a new array
  print(numbers.map((e) => e + 1).toList()); // (3, 9, 5, 7, 8, 4)
  
  / / the sort order
  numbers.sort((a, b) => a.compareTo(b));
  print(numbers); // [2, 3, 4, 6, 7, 8]
  
   // Where returns the set of elements in the array that meet the given criteria
  print(numbers.where((element) => element >= 6).toList()); / / [6, 7, 8]

  // firstWhere returns the first element in the array that satisfies the given condition
  print(numbers.firstWhere((element) => element >= 6)); / / 6

  // Returns the only element in the array that meets the given condition. If more than one element meets the condition, an exception is thrown
  print(numbers.singleWhere((element) => element >= 8)); / / 8
  
  // take(n) takes n elements from the array
  print(numbers.take(2).toList()); / / [2, 3]

  // skip(n) skip n elements in the array
  print(numbers.skip(2).toList()); // [4, 6, 7, 8]
  
    // expand the element
  numbers = [
    [1.2],
    [3.4]].print(numbers.expand((element) => element).toList()); // [1, 2, 3, 4]
  
  // Clone an array
  List.from(numbers);
  
Copy the code

Set

// constructor
Set(a)Set.from()
Set.identity()
Set.of
Set.unmodifiable
/ / propertyFirst hashCode isEmpty isNotEmpty iterator last Length runtimeType Single method add addAll any cast clear contains containsAll difference elementAt every expand firstWhere fold followedBy forEach intersection join lastWhere lookup map noSuchMethod reduce remove removeAll removeWhere retainAll retainWhere singleWhere skip skipWhile take takeWhile toList toSet toString union where whereTypeCopy the code

Map