Related Tags

intersect
julia
set
method
communitycreator

# How to use the intersect() method of a set in Julia

Programming Bytes

### Overview

The intersect method is used to find the intersectionThis returns a new set of elements that are common in the provided sets. of the given sets.

### Syntax

intersect(s, itrs...)


### Arguments

This method takes the sets as an argument.

### Return value

This method returns a set that contains the common elements of the provided argument sets.

### Code example

The code given below demonstrates how we can use the intersect method:

# intersection of two set
println(intersect(Set([1, 2]), Set([1, 4])))

# intersection of two set
println(intersect(Set([1, 2]), Set([3, 4])))

# intersection of two set
println(intersect(Set([1, 2]), Set([1, 2])))
Using the "intersect" method

### Code explanation

• Line 2: We use the intersect method to find the common elements between the sets [1,2] and [1,4]. The common elements between the two sets is 1, so a new set with [1] as an element is returned.

• Line 5: We use the intersect method to find the common elements between the sets [1,2] and [3,4]. There is no common element between these two sets, so an empty set is returned.

• Line 8: We use the intersect method to find the common elements between the sets [1,2] and [1,2]. The common elements between the two sets are 1 and 2, so a new set with [1, 2] as its elements is returned.

RELATED TAGS

intersect
julia
set
method
communitycreator

CONTRIBUTOR

Programming Bytes
RELATED COURSES

View all Courses

Keep Exploring

Learn in-demand tech skills in half the time