Sobes.tech
Junior

If the value in a Map is not needed, which collection is better to use instead of LinkedHashMap?

sobes.tech AI

Answer from AI

If the value in a Map is not needed, it is better to use a Set collection, as it only stores unique keys without values. In Flutter (Dart), the LinkedHashSet class is suitable for this, which preserves the order of element addition, similar to LinkedHashMap, but without values.

Example:

import 'dart:collection';

void main() {
  LinkedHashSet<String> set = LinkedHashSet<String>();
  set.add('apple');
  set.add('banana');
  set.add('apple'); // duplicate will not be added

  print(set); // {apple, banana}
}
If the value in a Map is not needed, which collection… - sobes.tech