How to find duplicate elements length in array flutter?

Solution 1:

here is your solution. [Null Safe]

void main() {
  List<int> items = [1, 1, 1, 2, 3, 4, 5, 5];

  Map<int, int> count = {};
  items.forEach((i) => count[i] = (count[i] ?? 0) + 1);

  print(count.toString()); // {1: 3, 2: 1, 3: 1, 4: 1, 5: 2}
}