The main method – contains element

In the following code snippet, the main method creates Set, invokes the New method, and adds elements 1 and 2. The check is done if element 1 exists in the set:

// main method
func main() {
var set *Set
set = &Set{}
set.New()
set.AddElement(1)
set.AddElement(2)
fmt.Println(set)
fmt.Println(set.ContainsElement(1))
}

Run the following command to execute the set.go file:

go run set.go

After executing the preceding command, we get the following output:

Let's take a look at the InterSect method in the next section.