From Wikipedia to Set (Mathematics)
A set is a set of clearly defined and different objects.
Perhaps the confusion stems from the fact that the set does not depend on how its elements are displayed. A set remains unchanged if its elements are supposedly repeated or reordered.
Thus, the programming languages ββthat I know will not put an element into a set if the element already belongs to it, or they would replace it if it already exists, but would never allow duplication.
Programming Language Examples
Let me offer some examples in different programming languages.
In python
A collection in Python is defined as an "unordered collection of unique elements." And if you declare a set as a = {1,2,2,3,4} , it will add only 2 to the set.
If you execute print(a) , the output will be {1,2,3,4} .
Haskell
In Haskell, the operation of inserting sets is defined as: "[...] if the set already contains an element equal to the given value, it is replaced by the new value."
Thus, if you do this: let a = fromList([1,2,2,3,4]) , if you type a in the main output, it will display [1,2,3,4] .
Java
Java suites define: "a collection that does not contain duplicate elements." Its adding operation is defined as: "adds the specified element to this set, if it is not already present [...] If this set already contains the element, the call leaves the parameter unchanged."
Set<Integer> myInts = new HashSet<>(asList(1,2,2,3,4)); System.out.println(myInts);
This code, as in other examples, will output [1,2,3,4] .