i have list string like this :
List<String> alphabet = [a,b,c];
then i add same string like : alphabet.add(a);
the result is [a,b,c,a]
the question is, How do I make sure the values ββin the string list
remain the same[a,b,c]
because the value a already exists in the string list
2
Answers
The easiest way is to check if the character is already contained before adding it.
Use
Set
(https://api.dart.dev/stable/3.1.3/dart-core/Set-class.html):Sets are like lists but automatically ignores duplicates, the best (and suggested) solution for your needs.
Also, you can convert it to
List
usingalphabet.toList()
;