C++
In C++, the Standard Template Library (STL) provides the std::set and std::unordered_set containers for representing sets. These containers offer member functions and algorithms for performing various set operations. Some common operations include:
insert(): Inserts an element into the set.erase(): Removes an element from the set.find(): Searches for an element in the set.size(): Returns the number of elements in the set.std::set_union,std::set_intersection,std::set_difference: Functions for performing set operations like union, intersection, and difference.
Java
In Java, the java.util package provides the Set interface and its various implementations such as HashSet, TreeSet, and LinkedHashSet. These implementations offer methods for set operations. Some common operations include:
add(): Adds an element to the set.remove(): Removes an element from the set.contains(): Checks if the set contains a specified element.size(): Returns the number of elements in the set.addAll(),retainAll(),removeAll(): Methods for performing set operations like union, intersection, and difference.